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

Commit 2852e59

Browse files
committed
Time: 519 ms (11.64%) | Memory: 29.1 MB (19.62%) - LeetSync
1 parent f0d1635 commit 2852e59

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+
class Solution:
2+
def maximumUniqueSubarray(self, nums: List[int]) -> int:
3+
visited = set()
4+
i = 0
5+
total = 0
6+
maxim = 0
7+
for r in range(len(nums)):
8+
if nums[r] not in visited:
9+
visited.add(nums[r])
10+
total +=nums[r]
11+
else:
12+
while i < r and nums[r] !=nums[i]:
13+
visited.discard(nums[i])
14+
total -=nums[i]
15+
i +=1
16+
i+=1
17+
18+
print(total, maxim)
19+
maxim = max(maxim, total)
20+
return maxim
21+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /