-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathq1508.py
More file actions
31 lines (25 loc) · 718 Bytes
/
q1508.py
File metadata and controls
31 lines (25 loc) · 718 Bytes
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
#!/usr/bin/python3
from typing import List
class Solution:
def rangeSum(self, nums: List[int], n: int, left: int, right: int) -> int:
prime = 1000000007
result = 0
newNums = []
for i in range(n):
sum = 0
for j in range(i, n):
sum += nums[j]
if sum >= prime:
sum %= prime
newNums.append(sum)
newNums.sort()
print(newNums)
for i in range(left - 1, right):
result += newNums[i]
if result >= prime:
result %= prime
return result
solu = Solution()
nums = [1,2,3,4]
result = solu.rangeSum(nums, 4, 1, 10)
print(result)