当前位置:网站首页>Force buckle 575 Divide candy
Force buckle 575 Divide candy
2022-07-06 22:04:00 【Big chicken legs are best】
Alice Yes n Piece sugar , Among them the first i The type of sugar is candyType[i] .Alice Notice that she's gaining weight , So I went to visit a doctor .
The doctor suggested Alice Eat less sugar , Just eat all her sugar n / 2 that will do (n It's an even number ).Alice I like these sweets very much , She wants to follow the doctor's advice , Eat as many different kinds of sugar as possible .
Give you a length of n Array of integers for candyType , return : Alice Eat only n / 2 In the case of sugar , You can eat sugar most Number of species .
Example 1:
Input :candyType = [1,1,2,2,3,3]
Output :3
explain :Alice Can only eat 6 / 2 = 3 Piece sugar , Because only 3 Seed sugar , She can eat one of each .
Example 2:
Input :candyType = [1,1,2,3]
Output :2
explain :Alice Can only eat 4 / 2 = 2 Piece sugar , No matter what kind of food she chooses to eat [1,2]、[1,3] still [2,3], She can only eat two different kinds of sugar .
Example 3:
Input :candyType = [6,6,6,6]
Output :1
explain :Alice Can only eat 4 / 2 = 2 Piece sugar , Although she can eat 2 gold , But you can only eat 1 Seed sugar .
source : Power button (LeetCode)
link :https://leetcode-cn.com/problems/distribute-candies
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
### Their thinking
Here is the solution
The minimum value of the number of optional candy types and half of the number of all tangs is returned
### Code
```javascript
/**
* @param {number[]} candyType
* @return {number}
*/
var distributeCandies = function(candyType) {
return Math.min(candyType.length/2,[...new Set(candyType)].length)
};
```
边栏推荐
- HDU 2008 digital statistics
- MPLS experiment
- What is the RDD operator in spark
- Oracle性能分析3:TKPROF简介
- mysql根据两个字段去重
- JS method to stop foreach
- Five wars of Chinese Baijiu
- 【10点公开课】:视频质量评价基础与实践
- 在Pi和Jetson nano上运行深度网络,程序被Killed
- AI enterprise multi cloud storage architecture practice | Shenzhen potential technology sharing
猜你喜欢

MPLS experiment

Enhance network security of kubernetes with cilium

基于LM317的可调直流电源
![关于char[]数组通过scanf赋值使用上的一些问题。。](/img/cf/d85a3172c5d29ac00377f9c30dbc4f.png)
关于char[]数组通过scanf赋值使用上的一些问题。。

GPS from getting started to giving up (19), precise ephemeris (SP3 format)

numpy 下载安装

Shake Sound poussera l'application indépendante de plantation d'herbe "louable", les octets ne peuvent pas oublier le petit livre rouge?

Sparkshuffle process and Mr shuffle process

The golden age of the U.S. technology industry has ended, and there have been constant lamentations about chip sales and 30000 layoffs

Unity3D学习笔记6——GPU实例化(1)
随机推荐
guava:Collections. The collection created by unmodifiablexxx is not immutable
ViT论文详解
Reinforcement learning - learning notes 5 | alphago
PostgreSQL modifies the password of the database user
UNI-Admin基础框架怎么关闭创建超级管理员入口?
50 commonly used numpy function explanations, parameters and usage examples
Embedded common computing artifact excel, welcome to recommend skills to keep the document constantly updated and provide convenience for others
Mongodb (III) - CRUD
[asp.net core] set the format of Web API response data -- formatfilter feature
GPS from getting started to giving up (XIII), receiver autonomous integrity monitoring (RAIM)
Sql: stored procedures and triggers - Notes
C# 如何在dataGridView里设置两个列comboboxcolumn绑定级联事件的一个二级联动效果
OpenCV300 CMake生成project在项目过程中的问题
MariaDb数据库管理系统的学习(一)安装示意图
基于LM317的可调直流电源
Set status bar style demo
make menuconfig出现recipe for target ‘menuconfig‘ failed错误
GPS from entry to abandonment (XVII), tropospheric delay
Huawei has launched attacks in many industries at the same time, and its frightening technology has made European and American enterprises tremble
Reptile practice (V): climbing watercress top250