You are viewing a single comment's thread. Return to all comments →
function lonelyinteger(a: number[]): number { if (a.length === 1) return a[0]; const arrMap = new Map<number, number>(); a.forEach((n:number) => (arrMap.has(n)) ? arrMap.set(n, (arrMap.get(n) + 1)) : arrMap.set(n, 1)); const iterator = arrMap.entries(); for (let i = 0; i < arrMap.size; i++){ const results = iterator.next().value; if (results[1] === 1) return results[0] } }
Seems like cookies are disabled on this browser, please enable them to open this website
Lonely Integer
You are viewing a single comment's thread. Return to all comments →