Skip to content

递增的三元子序列

LeetCode-334

js

var increasingTriplet = function(nums) {
  let len = nums.length
  let min = nums[0] // 最小值
  let secondMin = Infinity // 第二小
  for(let i = 1; i < len; i++) {
    if(nums[i] > secondMin) return true
    else if(nums[i] <= min) min = nums[i] // 当前值比min要小
    else secondMin = nums[i] // 当之前大于min
  }
  return false
}