leetcode575
public class Solution {
public int DistributeCandies(int[] candies) {
var dic = new Dictionary<int, int>();
var len=candies.Length;
var result = ;
foreach (var candy in candies)
{
if (!dic.ContainsKey(candy))
{
dic.Add(candy, );
}
else
{
dic[candy]++;
}
}
if (dic.Count >= len / )
{
result = len / ;
}
else
{
result = dic.Count;
}
return result;
}
}
https://leetcode.com/problems/distribute-candies/#/description
leetcode575的更多相关文章
- [Swift]LeetCode575. 分糖果 | Distribute Candies
Given an integer array with even length, where different numbers in this array represent different k ...
- Leetcode575.Distribute Candies分糖果
给定一个偶数长度的数组,其中不同的数字代表着不同种类的糖果,每一个数字代表一个糖果.你需要把这些糖果平均分给一个弟弟和一个妹妹.返回妹妹可以获得的最大糖果的种类数. 示例 1: 输入: candies ...
随机推荐
- Linux OpenCV 静态链接错误
错误一: undefined reference to `dlopen' undefined reference to `dlerror' undefined reference to `dlsym' ...
- HDU4035 Maze(师傅逃亡系列•二)(循环型 经典的数学期望)
When wake up, lxhgww find himself in a huge maze. The maze consisted by N rooms and tunnels connecti ...
- log4j的使用配置
1.与spring整合,web.xml中配置详情 <!-- 加载log4j的配置文件log4j.properties --> <context-param> <param ...
- (1/2) 为了理解 UWP 的启动流程,我从零开始创建了一个 UWP 程序
每次使用 Visual Studio 的模板创建一个 UWP 程序,我们会在项目中发现大量的项目文件.配置.应用启动流程代码和界面代码.然而这些文件在 UWP 程序中到底是如何工作起来的? 我从零开始 ...
- 1153 Decode Registration Card of PAT (25 分)
A registration card number of PAT consists of 4 parts: the 1st letter represents the test level, nam ...
- python 时间日期处理
refer to : http://www.wklken.me/posts/2015/03/03/python-base-datetime.html#datetime-string http://ww ...
- Python 三元条件判断表达式(and or/if else)
参考: http://wangye.org/blog/archives/690/
- redis 连接池的一些问题
问题: Could not get a resource from the pool 将配置修改为如下: JedisPoolConfig config =newJedisPoolConfig ...
- quick 状态机StateMachine
function Player:addStateMachine() self.fsm_ = {} cc.GameObject.extend(self.fsm_) :addComponent(" ...
- C++中const使用注意要点(一)
最近看<C++编程思想>发现自己的基础确实不牢固,也想起了以前写代码时也因为const的事情浪费过时间,这里总结下几个要点. 首先说下内部链接和外部链接. 当一个cpp文件在编译时,预处理 ...