当前位置:网站首页>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)
};
```
边栏推荐
- Reset Mikrotik Routeros using netinstall
- GPS from getting started to giving up (19), precise ephemeris (SP3 format)
- GPS du début à l'abandon (XIII), surveillance autonome de l'intégrité du récepteur (raim)
- [daily] win10 system setting computer never sleeps
- Tiktok will push the independent grass planting app "praiseworthy". Can't bytes forget the little red book?
- OpenCV300 CMake生成project在项目过程中的问题
- GPS from getting started to giving up (XV), DCB differential code deviation
- 11、 Service introduction and port
- MySQL - transaction details
- GPS从入门到放弃(十六)、卫星时钟误差和卫星星历误差
猜你喜欢
GPS从入门到放弃(十七) 、对流层延时
JPEG2000-Matlab源码实现
Basic introduction of figure
数字化转型挂帅复产复工,线上线下全融合重建商业逻辑
20 large visual screens that are highly praised by the boss, with source code templates!
Unity3D学习笔记6——GPU实例化(1)
关于char[]数组通过scanf赋值使用上的一些问题。。
Tiktok will push the independent grass planting app "praiseworthy". Can't bytes forget the little red book?
Unity3d Learning Notes 6 - GPU instantiation (1)
GNN, please deepen your network layer~
随机推荐
bat脚本学习(一)
Reinforcement learning - learning notes 5 | alphago
一行代码可以做些什么?
【sciter】: 基于 sciter 封装通知栏组件
20 large visual screens that are highly praised by the boss, with source code templates!
GPS from getting started to giving up (XV), DCB differential code deviation
[10:00 public class]: basis and practice of video quality evaluation
Mysql相关术语
mysql根据两个字段去重
Five wars of Chinese Baijiu
[MySQL] online DDL details
MariaDB database management system learning (I) installation diagram
[Digital IC manual tearing code] Verilog automatic beverage machine | topic | principle | design | simulation
High precision face recognition based on insightface, which can directly benchmark hongruan
GPS從入門到放弃(十三)、接收機自主完好性監測(RAIM)
Is it important to build the SEO foundation of the new website
Aggregate function with key in spark
Bat script learning (I)
About the professional ethics of programmers, let's talk about it from the way of craftsmanship and neatness
GPS从入门到放弃(十五)、DCB差分码偏差