Count of Range Sum LeetCode solution in Python

1
class Solution:
2
def countRangeSum(self, nums: List[int], lower: int, upper: int) -> int:
3
acc = list(accumulate(nums))
4
ans = a = 0
5
for n in nums:
6
a += n
7
ans += sum(1 for x in acc if lower <= x <= upper)
8
acc.pop(0)
9
lower += n
10
upper += n
11
return ans

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0