# 137. 只出现一次的数字 II

var singleNumber = function(nums) {
  const map = {};
  for (let i = 0; i < nums.length; i++) {
    if (map[nums[i]]) {
      if (map[nums[i]] == 2) delete map[nums[i]];
      else map[nums[i]] += 1;
    } else map[nums[i]] = 1;
  }

  return Object.keys(map)[0];
};

const nums = [2, 2, 3, 2];
const nums2 = [0, 1, 0, 1, 0, 1, 99];

// console.log(singleNumber(nums));
console.log(singleNumber(nums2));
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Last Updated: 6/27/2023, 7:40:45 PM