Maximum Erasure Value LeetCode solution in Java

1
class Solution {
2
public int maximumUniqueSubarray(int[] nums) {
3
short[] nmap = new short[10001];
4
int total = 0, best = 0;
5
for (int left = 0, right = 0; right < nums.length; right++) {
6
nmap[nums[right]]++;
7
total += nums[right];
8
while (nmap[nums[right]] > 1) {
9
nmap[nums[left]]--;
10
total -= nums[left++];
11
}
12
best = Math.max(best, total);
13
}
14
return best;
15
}
16
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0