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 575. 分糖果
最新推荐文章于 2024-02-07 15:49:45 发布