MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / NumArray

Class NumArray

303-Range_Sum_Query/Range_Sum_Query.py:3–10  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1from typing import List
2
3class NumArray:
4 def __init__(self, nums: List[int]):
5 self.prefix_sum = [0]*(len(nums)+1)
6 for i in range(len(nums)):
7 self.prefix_sum[i+1] = self.prefix_sum[i]+nums[i]
8
9 def sumRange(self, left: int, right: int) -> int:
10 return self.prefix_sum[right+1]-self.prefix_sum[left]

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected