nikunjsoni

78

Jul 14th, 2021
98
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Solution {
  2. public:
  3.     void backtrack(vector<vector<int>> &ans, vector<int> &nums, int start, vector<int> &temp){
  4.         ans.push_back(temp);
  5.         for(int i=start;i<nums.size();i++){
  6.             temp.push_back(nums[i]);
  7.             backtrack(ans, nums, i+1, temp);
  8.             temp.pop_back();
  9.         }
  10.     }
  11.     vector<vector<int>> subsets(vector<int>& nums) {
  12.         ios_base::sync_with_stdio(false);
  13.         cin.tie(NULL);
  14.         vector<vector<int>> ans;
  15.         vector<int> temp;
  16.         backtrack(ans, nums, 0, temp);
  17.         return ans;
  18.     }
  19. };
RAW Paste Data