Created
March 5, 2021 15:12
-
-
Save MohammedALREAI/84764670a40fa82fcfbff8366bc7af21 to your computer and use it in GitHub Desktop.
137. Single Number II leetcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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