leetcode575

Posted AsenYang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode575相关的知识,希望对你有一定的参考价值。

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

以上是关于leetcode575的主要内容,如果未能解决你的问题,请参考以下文章

[leetcode-575-Distribute Candies]

leetcode575

LeetCode 575. Distribute Candies (发糖果)

LeetCode解题思路:575. Distribute Candies

Leetcode 575. Distribute Candies

Leetcode 575. Distribute Candies