Javascript 148ms


  • 0
    M

    var removeDuplicates = function(nums) {

    //two pointers, one pass
    var slow = 0;
    for (var fast = 0; fast < nums.length; fast++) {
        if (nums[slow] !== nums[fast]) {
            nums[++slow] = nums[fast];
        }
    }
    return slow+1;
    

    };


Log in to reply
 

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