Skip to content

Latest commit

 

History

History
28 lines (19 loc) · 329 Bytes

268. 丢失的数字.md

File metadata and controls

28 lines (19 loc) · 329 Bytes

思路

位运算

代码

var missingNumber = function(nums) {
  let res = 0, n = nums.length;
  for(let i = 0; i <= n; i ++) {
    let cur = nums[i];
    if (i != n) {
      res ^= cur;
    }
    res ^= i;
  }
  return res
};

复杂度分析

事件复杂度 $O(N)$

空间复杂度 $O(1)$