303. Range Sum Query - Immutable
[Easy] “Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive."
Note: old solution, should review (TODO:
)
Python3:
# Your NumArray object will be instantiated and called as such:
# obj = NumArray(nums)
# param_1 = obj.sumRange(i,j)
class NumArray:
def __init__(self, nums: List[int]):
self.nums = nums
def sumRange(self, i: int, j: int) -> int:
return sum(self.nums[i:j + 1])