334. Increasing Triplet Subsequence

比較的對象不用連續

class Solution {

    /**
     * @param Integer[] $nums
     * @return Boolean
     */
    function increasingTriplet($nums) {
        $second = max($nums);
        $third = max($nums);
        foreach($nums as $index => $num) {
            if ($num <= $second) {
                $second = $num;
            } elseif ($num <= $third) {
                $third = $num;
            } else {
                return true;
            }
        }    

        return false;
    }
}

Last updated