Skip to content

Commit 8ed8a35

Browse files
authored
Create Maximum Unique Subarray Sum After Deletion.java
1 parent 72f877e commit 8ed8a35

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public int maxSum(int[] nums) {
3+
int max = nums[0];
4+
int sum = 0;
5+
Set<Integer> set = new HashSet<>();
6+
for (int num : nums) {
7+
max = Math.max(num, max);
8+
if (num > 0 && set.add(num)) {
9+
sum += num;
10+
}
11+
}
12+
if (max < 0) {
13+
return max;
14+
}
15+
return sum;
16+
}
17+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy