Skip to content

Commit

Permalink
Add solution for Range Sum Query - Immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
Blacknahil committed Feb 8, 2024
1 parent 504e837 commit 0caa0fd
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions week9/leetcode/range-sum-query-immutable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class NumArray:

def __init__(self, nums: List[int]):
self.prefix=[0]
for num in nums:
self.prefix.append(self.prefix[-1] + num)
def sumRange(self, left: int, right: int) -> int:
return self.prefix[right+1] - self.prefix[left]



# Your NumArray object will be instantiated and called as such:
# obj = NumArray(nums)
# param_1 = obj.sumRange(left,right)

0 comments on commit 0caa0fd

Please sign in to comment.