Skip to content

Commit bc58961

Browse files
authored
feat: update cpp solution to lc problem: No.0026 (#700)
1 parent 20aa6df commit bc58961

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

solution/0000-0099/0026.Remove Duplicates from Sorted Array/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,16 @@ public:
120120
};
121121
```
122122
123+
```cpp
124+
class Solution {
125+
public:
126+
int removeDuplicates(vector<int>& nums) {
127+
nums.erase(unique(nums.begin(), nums.end()), nums.end());
128+
return nums.size();
129+
}
130+
};
131+
```
132+
123133
### **Go**
124134

125135
```go
Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
class Solution {
22
public:
33
int removeDuplicates(vector<int>& nums) {
4-
int i = 0;
5-
for (int& num : nums)
6-
if (i < 1 || num != nums[i - 1])
7-
nums[i++] = num;
8-
return i;
4+
nums.erase(unique(nums.begin(), nums.end()), nums.end());
5+
return nums.size();
96
}
10-
};
7+
};

0 commit comments

Comments
 (0)