-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathGetMaxScore.java
More file actions
47 lines (41 loc) · 956 Bytes
/
GetMaxScore.java
File metadata and controls
47 lines (41 loc) · 956 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class Solution {
public int maxSum(int[] nums1, int[] nums2) {
int n = nums1.length;
int m = nums2.length;
int i=0, j=0;
long si=0, sj=0;
long res = 0;
while(i<n && j<m)
{
if(nums1[i] < nums2[j])
{
si += nums1[i];
i++;
}
else if(nums1[i] > nums2[j])
{
sj += nums2[j];
j++;
}
else
{
res += Math.max(si, sj) + nums1[i];
i++;
j++;
si=0;
sj=0;
}
}
while(i<n)
{
si += nums1[i];
i++;
}
while(j<m)
{
sj += nums2[j];
j++;
}
return (int)((Math.max(si, sj) + res) % 1000000007);
}
}