leetcode -1103. 分糖果 II(python)

class Solution:
    def distributeCandies(self, candies: int, num_people: int) -> List[int]:
        if not candies:
            return []
        res=[0]*num_people
        j=1
        while candies>0:
            for i in range(num_people):
                if candies>j:
                    res[i]+=j
                else:
                    res[i]+=candies
                    candies=0
                    break
                candies-=j
                j+=1
        return res

猜你喜欢

转载自blog.csdn.net/qq_42738654/article/details/104684505