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 ...
随机推荐
- 编程之美Ex1——求二进制中1的个数
又被阿里机考虐了一次,决定改变策略开始刷题T^T 一个字节(8bit)的无符号整型,求其二进制中的“1”的个数,算法执行效率尽可能高. 最先想到的移位操作,末尾位&00000001,然后右移, ...
- navicat如何设置外键
今天上午刚刚弄明白了在navicat for mysql上如何设置外键,现在分享出来,希望能够对大家有帮助. 先介绍一下基本情况.现在有两个表一张是teacher表一张是dept表,现在我想把teac ...
- CentOS解压rar文件
默认不能解压rar文件. 进官网下载:http://www.rarsoft.com/download.htm RAR 5.40 for Linux x64 安装: # tar -zxvf rarlin ...
- conduit 安装试用
备注: 测试安装环境使用docker mac 版本(目前版本已经支持kubernetes了) 1. 基本安装 curl https://run.conduit.io/install | bash 配置 ...
- 怎样在windows下和linux下获取文件(如exe文件)的具体信息和属性
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/xmt1139057136/article/details/25620685 程序猿都非常懒.你懂的! ...
- smarty 模板编译和变量调节器 模板引入
<?php require './smarty/Smarty.class.php'; $sm = new Smarty; //$sm->force_compile = true; $sm- ...
- piezo film 压电相关信息记录 (2018-05-04 更新)
piezo film 压电相关信息记录 起因需要使用 Piezo 做一些设计 http://www.te.com.cn/chn-zh/videos/transportation/piezo-film- ...
- 【转】刚发现一个linux在线文档库。很好很强大。
原文网址:http://blog.csdn.net/longxibendi/article/details/6048231 1.网址: http://www.mjmwired.net 2.比如查看这个 ...
- 优化RequireJS项目(合并与压缩)
关于RequireJS已经有很多文章介绍过了.这个工具可以将你的JavaScript代码轻易的分割成苦 干个模块(module)并且保持你的代码模块化与易维护性.这样,你将获得一些具有互相依赖关系的J ...
- nginx虚拟机的配置
user nginx nginx;worker_processes 1;pid /data/var/run/nginx/nginx.pid;worker_rlimit_nofile 51200; ev ...