575. Distribute Candies
https://leetcode.com/problems/distribute-candies/description/
题目比较长,总结起来很简单:有个整型数组,长度是偶数,把它分成两份,要求有一份里面数字的多样性最大。
思路:一个很简单的思路是,数出有多少不一样的数字n,然后一份有多少个m,取两个的最小值就行。
class Solution {
public:
int distributeCandies(vector<int>& candies) {
if (candies.size() == ) return ;
std::sort(candies.begin(), candies.end());
int distinct = ;
for (int i = ; i < candies.size(); i++) {
if (candies[i-] != candies[i]) {
distinct++;
}
}
//how many candies for each one, since amount of candies is even and only split to 2 parts
int n = candies.size() / ;
return std::min(n, distinct);
}
};
575. Distribute Candies的更多相关文章
- LeetCode 575. Distribute Candies (发糖果)
Given an integer array with even length, where different numbers in this array represent different k ...
- LeetCode 575 Distribute Candies 解题报告
题目要求 Given an integer array with even length, where different numbers in this array represent differ ...
- [LeetCode&Python] Problem 575. Distribute Candies
Given an integer array with even length, where different numbers in this array represent different k ...
- 575. Distribute Candies 平均分糖果,但要求种类最多
[抄题]: Given an integer array with even length, where different numbers in this array represent diffe ...
- LeetCode: 575 Distribute Candies(easy)
题目: Given an integer array with even length, where different numbers in this array represent differe ...
- 【leetcode】575. Distribute Candies
原题 Given an integer array with even length, where different numbers in this array represent differen ...
- 【LeetCode】575. Distribute Candies 解题报告(Java & Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 Java解法 Python解法 日期 题目地址:ht ...
- 【Leetcode_easy】1103. Distribute Candies to People
problem 1103. Distribute Candies to People solution:没看明白代码... class Solution { public: vector<int ...
- LeetCode 1103. Distribute Candies to People
1103. Distribute Candies to People(分糖果||) 链接:https://leetcode-cn.com/problems/distribute-candies-to- ...
随机推荐
- docker容器网络
1.我们在使用docker run创建Docker容器时,可以用--net选项指定容器的网络模式,Docker有以下4种网络模式: · host模式,使用--net=host指定 · containe ...
- 退役之战- SDOI
嘻嘻, 从文化课中逃脱出来, 很痛苦啊, 英语已经近半年没学了,语文水平水的一批,在其他班里受虐待. 百废待兴. 因为曾经学了一段时间的省选,所以被老师拉回来送人头考试啦. 听说4.5 SDOI一轮哎 ...
- 【深度学习】RNN | GRU | LSTM
目录: 1.RNN 2.GRU 3.LSTM 一.RNN 1.RNN结构图如下所示: 其中: $a^{(t)} = \boldsymbol{W}h^{t-1} + \boldsymbol{W}_{e} ...
- 洛伦兹曲线(Lorenz curve)提升指数、提升表和提升图
sklearn实战-乳腺癌细胞数据挖掘 https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campai ...
- flink-conf.yaml
Flink 配置文件 对于管理员来说,差不多经常调整的就只有 conf 下的flink-conf.yaml : 经过初步的调整,大约有以下模块的参数(未优化) Licensed to the Apac ...
- zeppelin中连接hive和impala
连接Hive 新建interpreter default.driver = org.apache.hive.jdbc.HiveDriver default.url = jdbc:hive2://hos ...
- 分库分表后跨分片查询与Elastic Search
携程酒店订单Elastic Search实战:http://www.lvesu.com/blog/main/cms-610.html 为什么分库分表后不建议跨分片查询:https://www.jian ...
- 前端面试题整理—Webpack篇
1.什么是webpack,与grunt和gulp有啥不同 webpack是一个模块打包工具,在webpack里面一切皆模块 通过loader转换文件,通过plugin注入钩子,最后输出有多个模块组合成 ...
- MDK调试无法进入main()函数
今天在用MDK调试stm32时出现了无法进入main函数,进入startup文件的情况. 在网上查找资料时发现,MDK调试设置断点最多只能设置5个.在减少断点后,调试果然能够正常进入main()函数了 ...
- box-shaw四边阴影详解
四边设置: /*设置四边不同颜色外阴影*/ .element{ box-shadow:-10px 0 10px red, /*左边阴影*/ 10px 0 10px yellow, /*右边阴影*/ 0 ...