Skip to content

Commit c8fb6bf

Browse files
authored
Update 448-find-all-numbers-disappeared-in-an-array.js
1 parent 7f086bb commit c8fb6bf

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

448-find-all-numbers-disappeared-in-an-array.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,21 @@ const findDisappearedNumbers = function(nums) {
1515
}
1616
return arr;
1717
};
18+
19+
// another
20+
21+
/**
22+
* @param {number[]} nums
23+
* @return {number[]}
24+
*/
25+
const findDisappearedNumbers = function(nums) {
26+
for(let i = 0, len = nums.length; i < len; i++) {
27+
const idx = Math.abs(nums[i]) - 1
28+
nums[idx] = - Math.abs(nums[idx])
29+
}
30+
const res = []
31+
nums.forEach((e, i) => {
32+
if(e > 0) res.push(i + 1)
33+
})
34+
return res
35+
};

0 commit comments

Comments
 (0)