码迷,mamicode.com
首页 > 其他好文 > 详细

334. Increasing Triplet Subsequence

时间:2017-07-01 10:58:05      阅读:152      评论:0      收藏:0      [点我收藏+]

标签:blog   style   ret   tco   java   solution   code   int   boolean   

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

标签:blog   style   ret   tco   java   solution   code   int   boolean   

原文地址:http://www.cnblogs.com/apanda009/p/7101491.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!