Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function findUniqueNumber(nums) {
let memo = {};
for (let i = 0; i < nums.length; i++) {
const num = nums[i];
if (!memo[num]) {
memo[num] = 1;
} else {
memo[num] += 1;
}
}
return Object.keys(memo).reduce((unique,num) => {
return memo[num] === 1 ? Number(num) : unique;
}, NaN);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment