Skip to content

Commit b44ff15

Browse files
committed
July 25
1 parent cc97d3f commit b44ff15

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def maxSum(self, nums: list[int]) -> int:
3+
total, max_ = 0, float('-inf')
4+
seen = set()
5+
for num in nums:
6+
if num > 0 and num not in seen:
7+
total += num
8+
seen.add(num)
9+
max_ = max(max_, num)
10+
return total if total != 0 else max_
11+
12+
13+
def main():
14+
nums = [1, 2, 3, 4, 5]
15+
assert Solution().maxSum(nums) == 15
16+
17+
nums = [1, 1, 0, 1, 1]
18+
assert Solution().maxSum(nums) == 1
19+
20+
nums = [1, 2, -1, -2, 1, 0, -1]
21+
assert Solution().maxSum(nums) == 3
22+
23+
24+
if __name__ == '__main__':
25+
main()

2025-07-July-LeetCoding-Challenge/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
| July 21 | [1957. Delete Characters to Make Fancy String](https://leetcode.com/problems/delete-characters-to-make-fancy-string/) | Easy | Solved |
2828
| July 22 | [1695. Maximum Erasure Value](https://leetcode.com/problems/maximum-erasure-value/) | Medium | Solved |
2929
| July 23 | [1717. Maximum Score From Removing Substrings](https://leetcode.com/problems/maximum-score-from-removing-substrings/) | Medium | Solved |
30-
| July 24 | []() | | |
31-
| July 25 | []() | | |
30+
| July 24 | [2322. Minimum Score After Removals on a Tree](https://leetcode.com/problems/minimum-score-after-removals-on-a-tree/) | Hard | Unsolved |
31+
| July 25 | [3487. Maximum Unique Subarray Sum After Deletion](https://leetcode.com/problems/maximum-unique-subarray-sum-after-deletion/) | Easy | Solved |
3232
| July 26 | []() | | |
3333
| July 27 | []() | | |
3434
| July 28 | []() | | |
@@ -42,4 +42,4 @@
4242
| --- | --- | --- | --- |
4343
| Easy | 6 | 6 | 0 |
4444
| Medium | 10 | 9 | 1 |
45-
| Hard | 7 | 1 | 6 |
45+
| Hard | 8 | 1 | 7 |

0 commit comments

Comments
 (0)