Skip to content

Commit 8b0387a

Browse files
authored
Create maximum-unique-subarray-sum-after-deletion.cpp
1 parent 43b2a92 commit 8b0387a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Time: O(n)
2+
// Space: O(n)
3+
4+
// hash set
5+
class Solution {
6+
public:
7+
int maxSum(vector<int>& nums) {
8+
const int mx = ranges::max(nums);
9+
if (mx < 0) {
10+
return mx;
11+
}
12+
unordered_set<int> lookup(cbegin(nums), cend(nums));
13+
int result = 0;
14+
for (const auto& x : lookup) {
15+
if (x > 0) {
16+
result += x;
17+
}
18+
}
19+
return result;
20+
}
21+
};

0 commit comments

Comments
 (0)