JavaScript Solution, beat 70%


  • 0
    T
      let hash = {};
      for(var i = 0; i < nums.length; i++){
          if(hash[nums[i]]){
              hash[nums[i]] += 1;
          }
          else {
              hash[nums[i]] = 1;
          }
      }
      for(var h in hash){
          if(hash[h] === 1){
              return +h;
          }
      }
    };

  • 0
    Z

    This solution doesn't meet this requirement:

    Could you implement it without using extra memory?

    The hash table uses extra memory.


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.