https://leetcode.com/problems/single-number-iii/description/?envType=daily-question&envId=2024-05-31
/**
* @param {number[]} nums
* @return {number[]}
*/
var singleNumber = function (nums) {
if (nums.length === 2) return nums
const map = new Map()
const res = []
for (let num of nums) {
map.set(num, (map.get(num) || 0) + 1);
}
for (let [key, value] of map) {
if (value === 1) {
res.push(
key
)
}
}
return res
};
Top comments (0)