码迷,mamicode.com
首页 > 其他好文 > 详细

leetcode1109

时间:2019-07-07 14:41:33      阅读:85      评论:0      收藏:0      [点我收藏+]

标签:val   book   ict   span   nbsp   tco   end   base   solution   

 1 class Solution:
 2     def corpFlightBookings(self, bookings: List[List[int]], n: int) -> List[int]:
 3         dic = dict()
 4         for begin,end,val in bookings:
 5             if begin in dic:
 6                 dic[begin] += val
 7             else:
 8                 dic[begin] = val
 9             if (end+1) in dic:
10                 dic[end+1] -= val
11             else:
12                 dic[end+1] = -val
13         res = [0] * n
14         #print(dic)
15         baseval = 0
16         for i in range(n):
17             if (i+1) in dic:
18                 baseval += dic[(i+1)]
19             res[i] = baseval
20         return res

 

leetcode1109

标签:val   book   ict   span   nbsp   tco   end   base   solution   

原文地址:https://www.cnblogs.com/asenyang/p/11145985.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!