File tree 1 file changed +10
-9
lines changed
scripts/algorithms/M/Maximum Erasure Value
1 file changed +10
-9
lines changed Original file line number Diff line number Diff line change
1
+ // Runtime: 461 ms (Top 64.36%) | Memory: 127.1 MB (Top 40.21%)
1
2
class Solution {
2
3
public:
3
4
int maximumUniqueSubarray (vector<int >& nums) {
4
5
int curr_sum=0 , res=0 ;
5
-
6
- // set to store the elements
6
+
7
+ // set to store the elements
7
8
unordered_set<int > st;
8
-
9
+
9
10
int i=0 ,j=0 ;
10
11
while (j<nums.size ()) {
11
12
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
13
14
st.erase (nums[i]);
14
15
curr_sum-=nums[i];
15
16
i++;
16
17
}
17
- // Add the current element to set and curr_sum value
18
+ // Add the current element to set and curr_sum value
18
19
curr_sum+=nums[j];
19
20
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...
22
23
res = max (res, curr_sum);
23
24
}
24
-
25
+
25
26
return res;
26
27
}
27
- };
28
+ };
You can’t perform that action at this time.
0 commit comments