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種不同的糖果,最後也要返回最小值
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章