Skip to content

Commit 7ba0dd2

Browse files
committed
Time: 0 ms (100%), Space: 10.8 MB (91.85%) - LeetHub
1 parent 11126bb commit 7ba0dd2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
class Solution {
2+
public:
3+
int removeDuplicates(vector<int>& nums) {
4+
int n = nums.size();
5+
if (n == 1) return 1;
6+
7+
int curr = 0;
8+
bool second = true;
9+
10+
for (int i = 1; i<n; i++) {
11+
if (nums[i] != nums[curr]) second = false;
12+
else if (!second) continue;
13+
14+
second = !second;
15+
curr++;
16+
nums[curr] = nums[i];
17+
}
18+
19+
return curr+1;
20+
}
21+
};

0 commit comments

Comments
 (0)