Skip to content

Instantly share code, notes, and snippets.

@goish135
Created July 20, 2021 08:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goish135/7325ada18f6a22279653a8e30a52b81e to your computer and use it in GitHub Desktop.
Save goish135/7325ada18f6a22279653a8e30a52b81e to your computer and use it in GitHub Desktop.
# 370. Range addition
updates = [[1,3,2],[2,4,3],[0,2,-2]]
length = 5
# [-2,0,3,5,3]
initial_arr = [0]*length
for i in updates:
#print(i)
s,d,inc = i[0],i[1],i[2]
print(s,d,inc)
for j in range(s,d+1):
initial_arr[j]+=inc
print("result:",initial_arr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment