leetcode 575. 分糖果

class Solution(object):
    def distributeCandies(self, candies):
        """
        :type candies: List[int]
        :rtype: int
        """
        myset=set()#表示多少种类
        for i in candies:
            if  i not in myset:
                myset.add(i)
                if len(myset) is len(candies)//2:
                    break

        return min(len(myset),len(candies)//2)
注意,最后要取最小值,即假设  即使1000种不同的糖果,最后也要返回最小值

你可能感兴趣的:(leetcode)