My 108ms Javascript solution


  • 0
    E

    Here's my solution that takes 108ms to complete beating 100% of JS submissions.

    /**
     * @param {number[]} nums
     * @return {number}
     */
    var singleNumber = function(nums) {
        nums.sort(function  (a, b) {
          return a - b;
        });
        while(nums.length > 0) {
          var num = nums.shift();
            if(num !== nums[0]) {
            return num;
            } else {
            	nums.shift();
            }
        }
    };

Log in to reply
 

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