leetcode 26 Remove Duplicates from Sorted Array

#include<iostream>
#include<vector>

using namespace std;

class Solution{
public:
	int removeDuplicates(vector<int> &nums){
		int size = nums.size();		
		int index = 0;
		for(int i = 0; i<size ;i++){
			cout << "i  is:" << i << endl;
			if((nums[i] == nums[i-1])&& i >0){
				cout << "nums i is:" << nums[i] << endl;
				cout << "nums i-1 is:" << nums[i-1] << endl;
			//	i++;
				continue;
			}
			nums[index] = nums[i];	
			//i++;
			index++;
			cout << "index is:" <<index <<endl;
		}
		return index;
	}
};
int main(){
	Solution so;
	vector<int> nums = {1,1,2,3,3,4,4,5};
	cout << "the res is:" << so.removeDuplicates(nums) << endl;
}

上一篇:remove-duplicates-from-sorted-list


下一篇:mysql – 在列中的每个副本上递增计数器