Skip to content
javascript
var removeDuplicates = function(nums) {
    let k=0,counter=1
    for(let i=0;i<nums.length;i++){
        if(i==0){
            nums[k]=nums[i]
            k++
            continue
        }
        if(nums[i]==nums[i-1]){
            counter++
        }else{
            counter=1
        }
        //only keep those counter less than 2
        if(counter<=2){
            nums[k]=nums[i]
            k++
        }

    }
    return k
};