nikunjsoni

90

Jul 14th, 2021
148
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,vector<int> temp,int start){
  4.         ans.push_back(temp);
  5.         for(int i=start;i<nums.size();i++){
  6.             if(i>start && nums[i]==nums[i-1]){
  7.                 continue;
  8.             }
  9.             temp.push_back(nums[i]);
  10.             backtrack(ans,nums,temp,i+1);
  11.             temp.pop_back();
  12.         }
  13.     }
  14.     vector<vector<int>> subsetsWithDup(vector<int>& nums) {
  15.         ios_base::sync_with_stdio(false);
  16.         cin.tie(NULL);
  17.         sort(nums.begin(),nums.end());
  18.         vector<vector<int>> ans;
  19.         backtrack(ans,nums,{},0);
  20.         return ans;
  21.     }
  22. };
RAW Paste Data