Python. Seeding the sums with 0 makes the math easier

  • 0
    class NumArray(object):
        def __init__(self, nums):
            s = 0
            self.num_sums = [0]
            for n in nums:
                s += n
        def sumRange(self, i, j):
            return self.num_sums[j + 1] - self.num_sums[i]

Log in to reply

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