different simple C++ solution


  • 0
    B


    class Solution {
    public:
    int removeDuplicates(vector<int>& nums) {
    int index = 0;
    int start = 0;
    int end = nums.size();
    while(start<end){
    while(start>0 && start<end-1 && nums[start]==nums[start-1] && nums[start]==nums[start+1])start++;
    nums[index++]=nums[start++];
    }
    return index;
    }
    };


Log in to reply
 

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