O(n) space JavaScript solution


  • 0
    G
    /**
     * @param {number[]} nums
     * @return {number[]}
     */
    var findDisappearedNumbers = function(nums) {
        nums.forEach((num) => {
           const index = Math.abs(num) - 1;
           nums[index] = Math.abs(nums[index]) * -1; 
        });
        
        return nums.reduce((acc, num, index) => {
            if (num > 0)
                acc.push(index +  1);
            
            return acc;
        }, []);
    };
    

Log in to reply
 

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