Skip to content

Commit 39acb57

Browse files
committed
Runtime: 461 ms (Top 64.36%) | Memory: 127.1 MB (Top 40.21%)
1 parent 0ffd97b commit 39acb57

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed
Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
1+
// Runtime: 461 ms (Top 64.36%) | Memory: 127.1 MB (Top 40.21%)
12
class Solution {
23
public:
34
int maximumUniqueSubarray(vector<int>& nums) {
45
int curr_sum=0, res=0;
5-
6-
//set to store the elements
6+
7+
//set to store the elements
78
unordered_set<int> st;
8-
9+
910
int i=0,j=0;
1011
while(j<nums.size()) {
1112
while(st.count(nums[j])>0) {
12-
//Removing the ith element untill we reach the repeating element
13+
//Removing the ith element untill we reach the repeating element
1314
st.erase(nums[i]);
1415
curr_sum-=nums[i];
1516
i++;
1617
}
17-
//Add the current element to set and curr_sum value
18+
//Add the current element to set and curr_sum value
1819
curr_sum+=nums[j];
1920
st.insert(nums[j++]);
20-
21-
//res variable to keep track of largest curr_sum encountered till now...
21+
22+
//res variable to keep track of largest curr_sum encountered till now...
2223
res = max(res, curr_sum);
2324
}
24-
25+
2526
return res;
2627
}
27-
};
28+
};

0 commit comments

Comments
 (0)