class Solution {
public:
vector<int> path;
vector<vector<int>> result;
vector<vector<int>> findSubsequences(vector<int>& nums) {
traverse(nums,0);
return result;
}
void traverse(vector<int>& nums, int start_index){
if(start_index>=nums.size()) return;
unordered_map<int,int> map;
for(int i=start_index;i<nums.size();i++){
if(map.count(nums[i])!=0) continue;
if(path.size()>0&&nums[i]<path[path.size()-1]) continue;
path.push_back(nums[i]);
map[nums[i]]=1;
if(path.size()>1)
result.push_back(path);
traverse(nums,i+1);
path.pop_back();
}
}
};
刷题记录第九十四天-非递减子序列-利用map去重
最新推荐文章于 2024-11-03 20:27:08 发布