My JavaScript Solution (use splice)


  • 0
    var removeDuplicates = function(nums) {
        if(nums.length === 0 || nums.length === 1){
            return nums.length;
        }
        
        var i = 1;
        while(i < nums.length){
            if(nums[i-1] === nums[i]){
                nums.splice(i, 1);
            }else {
                i++;
            }
        }
        return nums.length;
    };
    

Log in to reply
 

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