Javascript solution


  • 0
    B
    var findErrorNums = function(nums) {
        var map = [];
        var ans = [];
        for(var i = 0; i < nums.length; i++){
            if(map[nums[i]] == undefined){
                map[nums[i]] = 1;
            } else {
                map[nums[i]] = map[nums[i]] + 1;
            }
        }
        
        for(var i = 1; i < map.length; i++){
            if(map[i] == undefined){
                ans[1] = i;
            }
            if(map[i] == 2){
                ans[0] = i;
            }
        }
        
        if(ans[1] == undefined){
            ans[1] = i;
        }
        return ans;
    };
    

Log in to reply
 

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