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

你可能感兴趣的:(leetcode)