Skip to content

Instantly share code, notes, and snippets.

@willshepp28
Last active December 16, 2020 22:22
Show Gist options
  • Save willshepp28/aa57ca9317a23f2dc637df2cb971da1a to your computer and use it in GitHub Desktop.
Save willshepp28/aa57ca9317a23f2dc637df2cb971da1a to your computer and use it in GitHub Desktop.
/**
* @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