algorithm notes: leetcode#370 range addition

Problem


Analysis


Solution


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class :
def getModifiedArray(self, length, updates):
"""
:type length: int
:type updates: List[List[int]]
:rtype: List[int]
"""
ans = [0] * (length+1)
for start, end, inc in updates:
ans[start] += inc
ans[end+1] -= inc
for i in range(1,len(ans)):
ans[i] += ans[i-1]
ans.pop()
return ans

370. Range Addition