Javascript code only beat 34.5%


  • 0
    J

    /**

    • @param {number[]} nums
    • @return {number}
      */
      var singleNumber = function(nums) {
      nums.sort();
      var i = 0;
      while (i < nums.length){
      if (nums[i+1] == null){
      return nums[i];
      }
      if (nums[i] == nums[i+1]){
      i = i+2;
      }
      else{
      return nums[i];
      }
      }
      };

Log in to reply
 

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