-
-
Notifications
You must be signed in to change notification settings - Fork 298
/
Copy path303.py
39 lines (30 loc) · 1.1 KB
/
303.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
__________________________________________________________________________________________________
sample 76 ms submission
class NumArray:
def __init__(self, nums: List[int]):
self.nums=nums
l=[]
s1=0
for i in range(len(nums)):
s1 += nums[i]
l.append(s1)
self.list=l
def sumRange(self, i: int, j: int) -> int:
if i==0:
return self.list[j]
else:
return self.list[j]-self.list[i-1]
# Your NumArray object will be instantiated and called as such:
# obj = NumArray(nums)
# param_1 = obj.sumRange(i,j)
__________________________________________________________________________________________________
sample 16444 kb submission
class NumArray:
def __init__(self, nums: List[int]):
self.n = nums
def sumRange(self, i: int, j: int) -> int:
return sum(self.n[i:j+1])
# Your NumArray object will be instantiated and called as such:
# obj = NumArray(nums)
# param_1 = obj.sumRange(i,j)
__________________________________________________________________________________________________