forked from kamyu104/LeetCode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-the-maximum-score.py
More file actions
26 lines (25 loc) · 814 Bytes
/
get-the-maximum-score.py
File metadata and controls
26 lines (25 loc) · 814 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
# Time: O(m + n)
# Space: O(1)
class Solution(object):
def maxSum(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: int
"""
MOD = 10**9+7
i, j = 0, 0
result, sum1, sum2 = 0, 0, 0,
while i != len(nums1) or j != len(nums2):
if i != len(nums1) and (j == len(nums2) or nums1[i] < nums2[j]):
sum1 += nums1[i]
i += 1
elif j != len(nums2) and (i == len(nums1) or nums1[i] > nums2[j]):
sum2 += nums2[j]
j += 1
else:
result = (result + (max(sum1, sum2) + nums1[i])) % MOD
sum1, sum2 = 0, 0
i += 1
j += 1
return (result + max(sum1, sum2)) % MOD