Simple JavaScript solution


  • 0
    U
    var findDisappearedNumbers = function(nums) {
    	let obj = {};
    	let arr = [];
    	let dis = [];
    	let len = nums.length;
    	for (let v of nums) {
                if (!(v in obj)) {
                     obj[v] = v;
                } else {
                     arr.push(v);
                }
    	}
    	for (let i = 1; i <= len; i++) {
    		if (!obj[i]) dis.push(i);
    	}
    	return dis;
    };
    

  • 0
    S

    there is no TLE?
    the same idea of u , but my code is LTE


Log in to reply
 

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