Simple JavaScript solution


  • 1
    L
    function increasingTriplet(nums) {
    
      var m; // mininum
      var m2; // sec mininum
    
      for (var i = 0; i < nums.length; i++) {
        var n = nums[i];
        if (m === undefined || n <= m) {
          m = n;
        } else /* n > m */ {
          if (m2 === undefined || n <= m2) {
            m2 = n;
          } else {
            return true;
          }
        }
      }
      return false;
    }

  • 0
    L
    // condensed version
    function increasingTriplet(nums) {
      for (var m, m2, i = 0; i < nums.length; i++) {
        if (m === undefined || nums[i] <= m) m = nums[i];
        else if (m2 === undefined || nums[i] <= m2) m2 = nums[i];
        else return true;
      }
      return false;
    }

Log in to reply
 

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