-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path491-Increasing-Subsequences.cpp
More file actions
42 lines (32 loc) · 1.26 KB
/
491-Increasing-Subsequences.cpp
File metadata and controls
42 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
class Solution {
public:
vector<vector<int>> findSubsequences(vector<int>& nums) {
set<vector<int>> ans;
vector<int> reg;
dfs(nums, reg, ans, 0);
return vector<vector<int>>(ans.begin(), ans.end());
}
void dfs(vector<int> &nums, vector<int>& arr, set<vector<int>>& answer, int idx){
if(arr.size() >= 2){
answer.insert(arr);
}
for(int i=idx; i<nums.size(); ++i){
if(arr.size() == 0 || nums[i] >= arr.back()){
arr.push_back(nums[i]);
dfs(nums, arr, answer, i+1);
arr.pop_back();
}
}
}
};
/* 491. Increasing-Subsequences.cpp
//////////////////////////////////////////////////
Given an integer array nums, return all the different possible increasing subsequences of the given array with at least two elements.
You may return the answer in any order.
The given array may contain duplicates, and two equal integers should also be considered a special case of increasing sequence.
Example 1:
Input: nums = [4,6,7,7]
Output: [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7],[6,7,7],[7,7]]
https://leetcode.com/problems/increasing-subsequences/
//////////////////////////////////////////////////
*/