Description
Submission
class Solution {
set<vector<int>> Set;
void dfs(vector<int>& nums, vector<int> &cur, int idx) {
if(idx == nums.size()) {
if(cur.size() >= 2) {
Set.insert(cur);
}
return;
}
// take the current
if(cur.empty() || cur.back() <= nums[idx]) {
cur.push_back(nums[idx]);
dfs(nums, cur, idx + 1);
cur.pop_back();
}
// don't take the current
dfs(nums, cur, idx + 1);
}
public:
vector<vector<int>> findSubsequences(vector<int>& nums) {
vector<int> cur;
dfs(nums, cur, 0);
return {Set.begin(), Set.end()};
}
};