78. 子集

遍历全部,不用终止条件

  1. class Solution {
  2. public:
  3. void backtracking(vector<int>& nums,int startIndex)
  4. {
  5. result.push_back(path);
  6. for(int i=startIndex;i<nums.size();i++)
  7. {
  8. path.push_back(nums[i]);
  9. backtracking(nums,i+1);
  10. path.pop_back();
  11. }
  12. }
  13. vector<vector<int>> subsets(vector<int>& nums) {
  14. backtracking(nums,0);
  15. return result;
  16. }
  17. vector<int> path;
  18. vector<vector<int>> result;
  19. };