Skip to content

Latest commit

 

History

History
23 lines (23 loc) · 701 Bytes

334.md

File metadata and controls

23 lines (23 loc) · 701 Bytes

334. Increasing Triplet Subsequence

题目链接

public class Solution {
    public boolean increasingTriplet(int[] nums) {
        // 设置两个变量,用来记录最小的和中间的值
        int small = Integer.MAX_VALUE;
        int middle = Integer.MAX_VALUE;
        for (int num : nums) {
            if (num <= small) {
                small = num;
            } else if (num <= middle) {
                middle = num;
            }
            // 如果数比这两个都大,返回true
            else {
                return true;
            }
        }
        return false;
    }
}