# Problem 491: Increasing Subsequences

> <https://leetcode.com/problems/increasing-subsequences/#/description>

## 思路

* 通过用 set 来去除重复元素
* 退出条件很 tricky，只要 path 的元素个数大于 2 就可以了。**注意：这里不需要退出！如果在这里 return 了，只能得到元素个数为 2 的一组数。**

```java
public class Solution {
    public List<List<Integer>> findSubsequences(int[] nums) {
        if (nums == null || nums.length == 0) {
            return new ArrayList();
        }
        Set<List<Integer>> rstSet = new HashSet<List<Integer>>();
        List<Integer> path = new ArrayList<Integer>();

        helper(nums, 0, path, rstSet);
        List rst = new ArrayList(rstSet);

        return rst;
    }

    private void helper(int[] nums, int index, List<Integer> path, Set<List<Integer>> rstSet) {
        if (path.size() >= 2) {
            rstSet.add(new ArrayList(path));
        }

        for (int i = index; i < nums.length; i++) {
            if (path.size() == 0 || nums[i] >= path.get(path.size() - 1)) {
                path.add(nums[i]);
                helper(nums, i + 1, path, rstSet);
                path.remove(path.size() - 1);
            }
        }
    }
}
```


---

# Agent Instructions: 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/chapter_1_combination_and_permutation/combination/problem-491-increasing-subsequences.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.
