Generation

generate functionThu, 17 Nov 2022

Single number

Script function singleNumber(nums) { let cache = {}; let arr = []; nums.forEach(num => { if (cache[num]) { cache[num] += 1; } else { cache[num] = 1; } }) for (let key in cache) { if (cache[key] === 1) { arr.push(key); } } return arr[0]; }

Questions about programming?Chat with your personal AI assistant