DEV Community

ZeeshanAli-0704
ZeeshanAli-0704

Posted on

Single Number - Unique one

let singleNumber = function(nums){
    let map = {}
    for(let i=0;i<nums.length-1;i++){
        if(map[nums[i]]) map[nums[i]] = false;
        else map[nums[i]] = true;
     }
     for(let [key, value] of Object.entries(map)){
         if(value) return key;
     }
     return -1;
}
Enter fullscreen mode Exit fullscreen mode

Top comments (0)