My easy c++ solution


  • 2
    V
    int removeDuplicates(vector<int>& nums) {
    	if (nums.size() <= 2)
    		return nums.size();
    	for (int i = 2; i < nums.size(); i++) {
    		if (nums[i] == nums[i - 1] && nums[i] == nums[i - 2]) {
    			vector<int>::iterator it = nums.begin() + i;
    			nums.erase(it);
    			i--;
    		}
    	}
    	return nums.size();
    }

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.