Simple Python Solution


  • 0
    Y
    class NumArray(object):
        def __init__(self, nums):
            self.nums = nums
            for i in range(1,len(self.nums)):
                self.nums[i] = self.nums[i] + self.nums[i - 1]
    
        def sumRange(self, i, j):
            if i == 0:
                return self.nums[j]
            return self.nums[j] - self.nums[i-1]

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.