当前位置:网站首页>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从入门到放弃(十七) 、对流层延时
- 小满网络模型&http1-http2 &浏览器缓存
- Oracle性能分析3:TKPROF简介
- 抖音將推獨立種草App“可頌”,字節忘不掉小紅書?
- uni-app App端半屏连续扫码
- MySQL removes duplicates according to two fields
- 关于char[]数组通过scanf赋值使用上的一些问题。。
- GNN, please deepen your network layer~
- Michael smashed the minority milk sign
- VIP case introduction and in-depth analysis of brokerage XX system node exceptions
猜你喜欢
Why is the cluster mode of spark on Yan better than the client mode
GNN,请你的网络层数再深一点~
Search element topic (DFS)
About the professional ethics of programmers, let's talk about it from the way of craftsmanship and neatness
Reptile practice (V): climbing watercress top250
[Chongqing Guangdong education] Tianjin urban construction university concrete structure design principle a reference
Vit paper details
JPEG2000 matlab source code implementation
搜素专题(DFS )
[Yu Yue education] higher mathematics of Nanchang University (2) reference materials
随机推荐
Reinforcement learning - learning notes 5 | alphago
What can one line of code do?
Set status bar style demo
string的底层实现
MongoDB(三)——CRUD
Unity3d Learning Notes 6 - GPU instantiation (1)
Michael smashed the minority milk sign
Enhance network security of kubernetes with cilium
C language: comprehensive application of if, def and ifndef
GPS从入门到放弃(十七) 、对流层延时
Sparkshuffle process and Mr shuffle process
[Yu Yue education] higher mathematics of Nanchang University (2) reference materials
GPS from getting started to giving up (19), precise ephemeris (SP3 format)
zabbix 代理服务器 与 zabbix-snmp 监控
Earned value management EVM detailed explanation and application, example explanation
What about the spectrogram
GPS from getting started to giving up (XVIII), multipath effect
用aardio写一个旋转验证码标注小工具
MariaDb数据库管理系统的学习(一)安装示意图
Powerful domestic API management tool