LC 448. Find All Numbers Disappeared in an Array

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





评论和交流请发送邮件到 me@tianhegao.com





通过以下渠道赞赏此文