Skip to content

Commit 01d6a93

Browse files
add 1695
1 parent d65452e commit 01d6a93

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ _If you like this project, please leave me a star._ ★
8484
|1705|[Maximum Number of Eaten Apples](https://leetcode.com/problems/maximum-number-of-eaten-apples/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1705.java) ||Medium|Heap, Greedy|
8585
|1704|[Determine if String Halves Are Alike](https://leetcode.com/problems/determine-if-string-halves-are-alike/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1704.java) ||Easy|String|
8686
|1700|[Number of Students Unable to Eat Lunch](https://leetcode.com/problems/number-of-students-unable-to-eat-lunch/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1700.java) ||Easy|Array|
87+
|1695|[Maximum Erasure Value](https://leetcode.com/problems/maximum-erasure-value/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1695.java) ||Medium|Two Pointers|
8788
|1694|[Reformat Phone Number](https://leetcode.com/problems/reformat-phone-number/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1694.java) ||Easy|String|
8889
|1690|[Stone Game VII](https://leetcode.com/problems/stone-game-vii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1690.java) ||Medium|DP|
8990
|1689|[Partitioning Into Minimum Number Of Deci-Binary Numbers](https://leetcode.com/problems/partitioning-into-minimum-number-of-deci-binary-numbers/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_1689.java) ||Medium|Greedy|
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
public class _1695 {
7+
public static class Solution1 {
8+
public int maximumUniqueSubarray(int[] nums) {
9+
Set<Integer> set = new HashSet<>();
10+
int maxSum = 0;
11+
int runningSum = 0;
12+
for (int right = 0, left = 0; right < nums.length; right++) {
13+
if (set.add(nums[right])) {
14+
runningSum += nums[right];
15+
maxSum = Math.max(maxSum, runningSum);
16+
} else {
17+
while (left < right && set.contains(nums[right])) {
18+
set.remove(nums[left]);
19+
runningSum -= nums[left];
20+
left++;
21+
}
22+
set.add(nums[right]);
23+
runningSum += nums[right];
24+
}
25+
}
26+
return maxSum;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)