My JavaScript solution


  • 0
    S

    not good, because i used map;

    /**
     * @param {number[]} nums
     * @return {number}
     */
    var singleNumber = function(nums) {
        var map = {};
        for (var i = 0, len = nums.length; i < len; i++) {
            var key = nums[i];
            if (!map[key]) {
                map[key] = 1;
                continue;
            }
            if (map[key] === 1) {
                map[key] = 2;
                continue;
            }
            delete map[key];
        }
        for (var k in map) {
            return +k;
        }
    };

Log in to reply
 

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