Skip to content

Commit a35bac3

Browse files
authored
Create get-the-maximum-score.py
1 parent b484d50 commit a35bac3

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Python/get-the-maximum-score.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Time: O(m + n)
2+
# Space: O(1)
3+
4+
class Solution(object):
5+
def maxSum(self, nums1, nums2):
6+
"""
7+
:type nums1: List[int]
8+
:type nums2: List[int]
9+
:rtype: int
10+
"""
11+
MOD = 10**9+7
12+
i, j = 0, 0
13+
result, sum1, sum2 = 0, 0, 0,
14+
while i != len(nums1) or j != len(nums2):
15+
if i != len(nums1) and (j == len(nums2) or nums1[i] < nums2[j]):
16+
sum1 += nums1[i]
17+
i += 1
18+
elif j != len(nums2) and (i == len(nums1) or nums1[i] > nums2[j]):
19+
sum2 += nums2[j]
20+
j += 1
21+
else:
22+
result = (result + (max(sum1, sum2) + nums1[i])) % MOD
23+
sum1, sum2 = 0, 0
24+
i += 1
25+
j += 1
26+
return (result + max(sum1, sum2)) % MOD

0 commit comments

Comments
 (0)