Last active
December 16, 2020 22:22
-
-
Save willshepp28/aa57ca9317a23f2dc637df2cb971da1a to your computer and use it in GitHub Desktop.
This file contains 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
/** | |
* @param {number[]} nums | |
* @return {number} | |
*/ | |
var singleNumber = function(nums) { | |
let obj = {}; | |
for(let i = 0; i < nums.length; i++) { | |
if(!obj[nums[i]]) { | |
obj[nums[i]] = 1; | |
} else { | |
delete obj[nums[i]] | |
} | |
} | |
return Object.keys(obj)[0] | |
}; | |
singleNumber([2,2,1]) // 1 | |
singleNumber([4,1,2,1,2]) // 4 | |
singleNumber([1]) // 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment