leetcode26 C++ 20ms 删除排序数列中的重复元素
class Solution {
public:
int removeDuplicates(vector<int>& nums) {
if(nums.empty()){
return 0;
}
if(nums.size()==1){
return 1 ;
}
int left = 0;
int right = 1;
int temp=0;
while(right < nums.size()){
while(nums[left] == nums[right]){
right++;
if(right==nums.size()){
return left+1;
}
}
left++;
temp = nums[left];
nums[left] = nums[right];
nums[right] = temp;
right++;
}
return left+1;
}
};