删除排序数组中的重复数字
class Solution { public: /** * @param A: a list of integers * @return : return an integer */ int removeDuplicates(vector<int> &nums) { // write your code here int longs=nums.size(); int number=0; if(longs==0) return 0; else { int k=0; for(int i=0;i<longs-number;i++) { if(nums[i]==nums[i+1]) { k=0; while(nums[i]==nums[i+k]) k++; number=number+k-1; for(int j=i+1;j<longs-number;j++) nums[j]=nums[j+k-1]; nums[longs-number]=0; } } longs-=number; nums.resize(longs+1); return longs; } } };