Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. from itertools import accumulate
  2. class NumArray:
  3.  
  4. def __init__(self, nums: List[int]):
  5. self.dp = list(accumulate(nums))
  6.  
  7. def sumRange(self, i: int, j: int) -> int:
  8.  
  9. if i == 0:
  10. return self.dp[j]
  11. else:
  12. return self.dp[j] - ( self.dp[i-1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement