yokostan / Leetcode-Solutions

Doing exercise on Leetcode. Carry on!
0 stars 3 forks source link

Leetcode #334. Increasing Triplet Subsequence #266

Open yokostan opened 5 years ago

yokostan commented 5 years ago
class Solution {
    public boolean increasingTriplet(int[] nums) {
        if (nums == null || nums.length < 3) return false;
        int min = Integer.MAX_VALUE;
        int secondMin = Integer.MAX_VALUE;

        for (int i = 0; i < nums.length; i++) {
            if (nums[i] <= min) {
                min = nums[i];
            }
            else if (nums[i] <= secondMin) {
                secondMin = nums[i];
            }
            else return true;
        }
        return false;
    }
}