1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
var findErrorNums = function(nums) { let ex = new Array(nums.length); let dup,lost; for(num of nums){ if (!ex[num-1]){ ex[num-1]=1; }else{ dup=num; } } for(let i=0;i<nums.length;i++){ if(!ex[i]){ lost=i+1; break; } } return [dup, lost] };
|