Easy to Understand --> Efficient C++ code
Intuition\n Describe your first thoughts on how to solve this problem. \nHere we need to make subsets so for each element "Pick" and "Not Pick" decision needs t
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nHere we need to make subsets so for each element "Pick" and "Not Pick" decision needs to be taken. \n# Approach\n<!-- Describe your approach to solving the problem. -->\nThe entire approach is same as Subset I. \n\n- Just when we are about to not pick an element we need to not pick all the similar elements and increase the index \'i\'.\n\nAnd this job is done by the following code block -->\n```\nwhile(i+1 <nums.size() && nums[i]==nums[i+1]){\n            i++;\n        }\n```\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n*O(2^n)*\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n*O(n^2)*\n\nMy Subset I solution link \uD83D\uDC47\nhttps://leetcode.com/problems/subsets/solutions/3342538/100-beats-used-backtracking-efficient-c-code/\nPlease upvote if you find it helpful \u2B06\uFE0F\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>>ans;\n    void help(int i,vector<int>&nums,vector<int>&temp){\n        if(i==nums.size()){\n            ans.push_back(temp);\n            return;\n        }\n        temp.push_back(nums[i]);\n        help(i+1,nums,temp);\n        \n        temp.pop_back();\n        while(i+1 <nums.size() && nums[i]==nums[i+1]){\n            i++;\n        }\n        help(i+1,nums,temp);\n        \n    }\n    vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n        vector<int>temp;\n        sort(nums.begin(),nums.end());\n        help(0,nums,temp);\n        //sort(ans.begin(),ans.end());\n        return ans;\n    }\n};\n```
['C++']