My JavaScript solution


  • 0
    S

    not good

    /**
     * @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] = true;
            }
            else {
                delete map[key];
            }
        }
        var ret = [];
        for (var j in map) {
            ret.push(+j);
        }
        return ret;
    };

  • 0
    U

    /**

    • @param {number[]} nums
    • @return {number}
      */
      var singleNumber = function(nums) {
      var t = {}
      for (var i = 0; i < nums.length; i++) {
      t[nums[i]] = (t[nums[i]] || 0) + 1
      }
      var ret = []
      for (var k in t) {
      if (t[k] == 1) {
      ret.push(parseInt(k))
      }
      }
      return ret
      };

Log in to reply
 

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