Python solution beats 100%

  • 0

    class Solution(object):
    def countRangeSum(self, nums, lower, upper):
    :type nums: List[int]
    :type lower: int
    :type upper: int
    :rtype: int
    n = len(nums)
    sumR = [0]*(n+1)
    for i in range(n-1,-1,-1):
    sumR[i] = sumR[i+1]+nums[i]
    l = []
    res = 0
    for i in range(n):
    x = bisect.bisect_left(l,lower+sumR[i+1])
    y = bisect.bisect_right(l,upper+sumR[i+1])
    res+= y-x
    return res

Log in to reply

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