class Solution {
public:
/**
* @param A: a list of integers
* @return : return an integer
*/
int removeDuplicates(vector<int> &nums) {
// write your code here
if(nums.empty())
{
return 0;
}//if
int n = nums.size(),k=0;
for(int i=1;i<n;++i)
{
if(nums[i] != nums[k])
{
nums[++k] = nums[i];
}//if
}//for
nums.resize(k+1);
return k+1;
}
};
时间: 2024-10-05 03:04:10