1 class Solution:
 2     def distributeCandies(self, candies: int, num_people: int) -> 'List[int]':
 3         res = [0] * num_people
 4         t = 0
 5         while candies >= 0:
 6             for i in range(num_people):
 7                 t += 1
 8                 if candies >= t:
 9                     res[i] += t
10                     candies -= t
11                 else:
12                     res[i] += candies
13                     return res
14         return res
15             
16         

两层循环,外层循环每次增加分配的数量t,内层循环进行分配减少candies的数量。

posted on 2019-06-30 12:58  Sempron2800+  阅读(179)  评论(0编辑  收藏  举报