Skip to content

Instantly share code, notes, and snippets.

@MohammedALREAI
Created March 5, 2021 15:12
Show Gist options
  • Select an option

  • Save MohammedALREAI/84764670a40fa82fcfbff8366bc7af21 to your computer and use it in GitHub Desktop.

Select an option

Save MohammedALREAI/84764670a40fa82fcfbff8366bc7af21 to your computer and use it in GitHub Desktop.
137. Single Number II leetcode
function singleNumber(nums: number[]):number {
let map=new Map<number,number>()
for (const num of nums) {
if (map.has(num)) {
const nextCount = map.get(num) as number + 1
if (nextCount === 3) {
map.delete(num)
} else {
map.set(num, nextCount)
}
} else {
map.set(num, 1)
}
}
return map.keys().next().value
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment