标签:ret key return .com title int tco dict problem
public class Solution { public int DistributeCandies(int[] candies) { var dic = new Dictionary<int, int>(); var len=candies.Length; var result = 0; foreach (var candy in candies) { if (!dic.ContainsKey(candy)) { dic.Add(candy, 1); } else { dic[candy]++; } } if (dic.Count >= len / 2) { result = len / 2; } else { result = dic.Count; } return result; } }
https://leetcode.com/problems/distribute-candies/#/description
标签:ret key return .com title int tco dict problem
原文地址:http://www.cnblogs.com/asenyang/p/6829919.html