JavaScript solution - time O(n), space O(1)


  • 0
    G
    var removeDuplicates = function(nums) {
        let length = 0;
        
        nums.reduce((prev, current) => {
            if (current !== prev) {
                nums[length++] = current;
            }
            
            return current;    
        }, null);
        
        return length;
    };
    

Log in to reply
 

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