每日一题 LCR 079. 子集
LCR 079. 子集
主要应该考虑遍历的顺序
class Solution {
public:
vector<vector<int>> subsets(vector<int>& nums) {
vector<vector<int>> ans;
vector<int> temp;
dfs(nums,0,temp,ans);
return ans;
}
void dfs(vector<int> &nums,int cur,vector<int> &temp,vector<vector<int>> &ans){
ans.push_back(temp);
if(cur >= nums.size()){
return;
}
for(int i=cur;i<nums.size();++i){
temp.push_back(nums[i]);
dfs(nums,i+1,temp,ans);
temp.pop_back();
}
}
};