mirror of
https://github.com/huihut/interview.git
synced 2024-03-22 13:10:48 +08:00
14 lines
324 B
C++
14 lines
324 B
C++
class Solution {
|
|
public:
|
|
int removeDuplicates(vector<int>& nums) {
|
|
int n = nums.size(), pos = 0;
|
|
if(n <= 1)
|
|
return n;
|
|
for(int i = 0; i < n-1; ++i) {
|
|
if(nums[i] != nums[i+1]) {
|
|
nums[++pos] = nums[i+1];
|
|
}
|
|
}
|
|
return pos+1;
|
|
}
|
|
}; |