Skip to content

Commit 407a5d2

Browse files
authored
Update Maximum Unique Subarray Sum After Deletion.py
1 parent 0992e7d commit 407a5d2

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

Maximum Unique Subarray Sum After Deletion.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,30 @@ def maxSum(self, nums: List[int]) -> int:
3030
return res
3131

3232
---------------------------------------------------------------
33+
34+
class Solution:
35+
def maxSum(self, nums: List[int]) -> int:
36+
37+
38+
n = len(nums)
39+
haspos = False
40+
41+
for n in nums:
42+
if n>0:
43+
haspos= True
44+
break
45+
46+
if not haspos:
47+
return max(nums)
48+
49+
seen = set()
50+
51+
res = 0
52+
53+
for val in nums:
54+
if val not in seen and val>=0:
55+
res += val
56+
seen.add(val)
57+
58+
return res
59+

0 commit comments

Comments
 (0)