首页 > 代码库 > 334. Increasing Triplet Subsequence

334. Increasing Triplet Subsequence

https://leetcode.com/problems/increasing-triplet-subsequence/#/description

http://www.cnblogs.com/EdwardLiu/p/6092267.html

这个解法的思想也可以推广到任意 k k比较小或者为常数的情
况,毕竟对于常数 k O(k) = O(1).

public class Solution {
    public boolean increasingTriplet(int[] nums) {
        int small = Integer.MAX_VALUE, big = Integer.MAX_VALUE;
        for (int n : nums) {
            if (n <= small) {
                small = n;
            }
            else if (n <= big) {
                big = n;
            }
            else return true;
        }
        return false;
    }
}

  

334. Increasing Triplet Subsequence