Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit01d6a93

Browse files
add 1695
1 parentd65452e commit01d6a93

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
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|
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
packagecom.fishercoder.solutions;
2+
3+
importjava.util.HashSet;
4+
importjava.util.Set;
5+
6+
publicclass_1695 {
7+
publicstaticclassSolution1 {
8+
publicintmaximumUniqueSubarray(int[]nums) {
9+
Set<Integer>set =newHashSet<>();
10+
intmaxSum =0;
11+
intrunningSum =0;
12+
for (intright =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+
returnmaxSum;
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp