当前位置:网站首页>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)
};
```
边栏推荐
- Univariate cubic equation - relationship between root and coefficient
- string的底层实现
- [10:00 public class]: basis and practice of video quality evaluation
- Codeforces Round #274 (Div. 2) –A Expression
- Broadcast variables and accumulators in spark
- LeetCode学习记录(从新手村出发之杀不出新手村)----1
- 搜素专题(DFS )
- Run the deep network on PI and Jetson nano, and the program is killed
- Uni app app half screen continuous code scanning
- [MySQL] online DDL details
猜你喜欢
Microsoft technology empowerment position - February course Preview
50 commonly used numpy function explanations, parameters and usage examples
Persistence / caching of RDD in spark
make menuconfig出现recipe for target ‘menuconfig‘ failed错误
numpy 下载安装
Huawei has launched attacks in many industries at the same time, and its frightening technology has made European and American enterprises tremble
[Yu Yue education] higher mathematics of Nanchang University (2) reference materials
Why rdd/dataset is needed in spark
C# 如何在dataGridView里设置两个列comboboxcolumn绑定级联事件的一个二级联动效果
Uni app app half screen continuous code scanning
随机推荐
Vit paper details
Shake Sound poussera l'application indépendante de plantation d'herbe "louable", les octets ne peuvent pas oublier le petit livre rouge?
Basic introduction of figure
GPS from entry to abandonment (XIV), ionospheric delay
Leetcode learning records (starting from the novice village, you can't kill out of the novice Village) ---1
MySQL - transaction details
GPS from getting started to giving up (XVIII), multipath effect
Codeforces Round #274 (Div. 2) –A Expression
GPS从入门到放弃(十一)、差分GPS
Kohana 数据库
Is it important to build the SEO foundation of the new website
【MySQL】Online DDL详解
Search element topic (DFS)
Powerful domestic API management tool
20 large visual screens that are highly praised by the boss, with source code templates!
What a new company needs to practice and pay attention to
Microsoft technology empowerment position - February course Preview
【10点公开课】:视频质量评价基础与实践
What can one line of code do?
The relationship between root and coefficient of quadratic equation with one variable