当前位置:网站首页>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)
};
```
边栏推荐
- GPS du début à l'abandon (XIII), surveillance autonome de l'intégrité du récepteur (raim)
- MySQL - transaction details
- Shake Sound poussera l'application indépendante de plantation d'herbe "louable", les octets ne peuvent pas oublier le petit livre rouge?
- 基于InsightFace的高精度人脸识别,可直接对标虹软
- Run the deep network on PI and Jetson nano, and the program is killed
- Bat script learning (I)
- Sequoia China, just raised $9billion
- [MySQL] online DDL details
- Happy sound 2[sing.2]
- Univariate cubic equation - relationship between root and coefficient
猜你喜欢

Adjustable DC power supply based on LM317

Wechat red envelope cover applet source code - background independent version - source code with evaluation points function
![关于char[]数组通过scanf赋值使用上的一些问题。。](/img/cf/d85a3172c5d29ac00377f9c30dbc4f.png)
关于char[]数组通过scanf赋值使用上的一些问题。。

How does the uni admin basic framework close the creation of super administrator entries?

JPEG2000-Matlab源码实现

numpy 下载安装

爬虫实战(五):爬豆瓣top250

Reptile practice (V): climbing watercress top250

Microsoft technology empowerment position - February course Preview
![Leetcode topic [array] -118 Yang Hui triangle](/img/77/d8a7085968cc443260b4c0910bd04b.jpg)
Leetcode topic [array] -118 Yang Hui triangle
随机推荐
The underlying implementation of string
The golden age of the U.S. technology industry has ended, and there have been constant lamentations about chip sales and 30000 layoffs
Digital transformation takes the lead to resume production and work, and online and offline full integration rebuilds business logic
关于char[]数组通过scanf赋值使用上的一些问题。。
Realization of epoll reactor model
Basic introduction of figure
基于InsightFace的高精度人脸识别,可直接对标虹软
UNI-Admin基础框架怎么关闭创建超级管理员入口?
设置状态栏样式Demo
Adjustable DC power supply based on LM317
Depth first traversal (DFS) and breadth first traversal (BFS)
Leetcode learning records (starting from the novice village, you can't kill out of the novice Village) ---1
小满网络模型&http1-http2 &浏览器缓存
Codeforces Round #274 (Div. 2) –A Expression
What is the difference between animators and animators- What is the difference between an Animator and an Animation?
npm run dev启动项目报错 document is not defined
Earned value management EVM detailed explanation and application, example explanation
From campus to Tencent work for a year of those stumbles!
Wechat red envelope cover applet source code - background independent version - source code with evaluation points function
GPS从入门到放弃(十五)、DCB差分码偏差