3sum - output limited error - but I test on jsfiddle perfectly


  • 0
    X

    /**

    • @param {number[]} nums

    • @return {number[][]}
      */
      var threeSum = function (nums) {

      var length = nums.length,
      sorted = nums.sort(function (a, b) {
      return (a > b);
      });

      if (length < 3) {
      return [];
      }

      var result = [] , i , j , k;

      for(i = 0;i<length-2;i++){
      if(nums[i] > 0){
      i = length;
      } else {
      if(i > 0 && (nums[i] === nums[i-1])){

           }else{
               for(j = i;j<length-1;j++){
                   if(j>i && (nums[j] === nums[j-1])){
                       
                   } else if((nums[i] + nums[j]) > 0){
                       j = length;
                   } else {
                       for(k = j;k<length;k++){
                           if((nums[i] + nums[j] + nums[k]) > 0){
                               k = length;
                           }else if(k>j && (nums[k] === nums[k-1])) {
                               
                           }else {
                               if((nums[i] + nums[j] + nums[k]) === 0){
                                   result.push([nums[i] , nums[j] , nums[k]]);
                               }
                           }
                           
                       }
                   }
               }
           }
       }
      

      }

      return result;

    };

    this is my code, leetcode do not print input and output so I can't figure where I got wrong, my test cases all running perfectly, anyone can help me out here?


Log in to reply
 

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