class Solution {
public:
vector<vector<int>> res;
vector<int> temp;
void dfs(vector<int>& nums, int cur){
if(cur == nums.size()){
res.push_back(temp);
return;
}
temp.push_back(nums[cur]);
dfs(nums, cur + 1);
temp.pop_back(); //回溯
dfs(nums, cur + 1);
}
vector<vector<int>> subsets(vector<int>& nums) {
dfs(nums, 0);
return res;
}
};
LeetCode 78. 子集
最新推荐文章于 2024-11-17 21:01:01 发布