本题还是基本的回溯法。就是回溯函数的参数选择上要花点心思!
class Solution { public: void backTrack(vector<int> ans, vector<int> nums, vector<vector<int>>& res, int bgi) { for(int i = bgi; i<nums.size();i++) { ans.push_back(nums[i]); res.push_back(ans); backTrack(ans,nums,res,i+1); ans.pop_back(); } } vector<vector<int>> subsets(vector<int>& nums) { vector<vector<int>> res; vector<int> ans; int bgi = 0; backTrack(ans,nums,res,bgi); res.push_back({}); return res; } };