Simple Javascript Solution

  • 1

    Would love some feedback on more efficient implementations, but here is a pretty straight forward approach using a hash map.

    var singleNumber = function(nums) {
        let hash = {};
        for (let i = 0; i < nums.length; i++) {
            !hash.hasOwnProperty(nums[i]) ? hash[nums[i]] = nums[i] : delete hash[nums[i]];
        return parseInt(Object.keys(hash)[0]);

Log in to reply

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