关于删除数组中重复元素的lintcode代码
时间自由度为o(n),空间自由度为o(1);
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;
}
int n = nums.size(),k=0;
for(int i=1;i<n;++i)
{
if(nums[i] != nums[k])
{
nums[++k] = nums[i];
}
}
nums.resize(k+1);
return k+1;
}
};