> For the complete documentation index, see [llms.txt](https://liuyang89116.gitbook.io/my-leetcode-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://liuyang89116.gitbook.io/my-leetcode-book/post_chapter_3_array/problem_334_increasing_triplet_subsequence.md).

# Problem 334: Increasing Triplet Subsequence

> <https://leetcode.com/problems/increasing-triplet-subsequence/>

## 思路

* 要想有一个递增的数列，至少前面有两个数字（最小的，第二小的），来判断第三个数字
* 可以维护两个值：最小值和倒数第二小的值；但是怎么满足，最小，第二小，最大这个顺序呢？我们可以用 if - else if - else 这个条件判断来实现

```java
public class Solution {
    public boolean increasingTriplet(int[] nums) {
        if (nums == null || nums.length < 3) {
            return false;
        } 

        int smallest = Integer.MAX_VALUE;
        int smaller = Integer.MAX_VALUE;
        for (Integer num : nums) {
            if (num <= smallest) {
                smallest = num;
            } else if (num <= smaller) {
                smaller = num;
            } else {
                return true;
            }
        }

        return false;
    }
}
```

## 易错点

1. 维护那两个元素的时候，要把他们事先设置为最大。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://liuyang89116.gitbook.io/my-leetcode-book/post_chapter_3_array/problem_334_increasing_triplet_subsequence.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
