Tianhe Gao

LC 448. Find All Numbers Disappeared in an Array

 1/**
 2 * @param {number[]} nums
 3 * @return {number[]}
 4 */
 5var findDisappearedNumbers = function(nums) {
 6  const n = nums.length
 7  for (const num of nums) {
 8    const x = (num - 1) % n
 9    nums[x] += n
10  }
11  const ret = []
12  for (const [i, num] of nums.entries()) {
13    if (num <= n) {
14      ret.push(i + 1)
15    }
16  }
17  return ret
18};

No notes link to this note

Welcome to tell me your thoughts via "email"
UP