What's wrong with my answer?

  • 0

    class NumArray(object):
    def init(self, nums):
    initialize your data structure here.
    :type nums: List[int]

    def sumRange(self, i, j):
        sum of elements nums[i..j], inclusive.
        :type i: int
        :type j: int
        :rtype: int
        sums = 0
        for k in range(i,j+1):
        return sums

  • 0

    Note:There are many calls to sumRange function.

    you need save sum of elements nums[0....j] to sum[j].

    so sumRange(i,j)=sums[j]-sums[i-1], just need a sub operation.

Log in to reply

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