C++ recursive and iterative
To skip duplicates, sort nums.\n\nRecursive (Backtracking)\n\ncpp\nclass Solution {\npublic:\n    vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n     
To skip duplicates, sort `nums`.\n\n**Recursive (Backtracking)**\n\n```cpp\nclass Solution {\npublic:\n    vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        vector<vector<int>> subs;\n        vector<int> sub;\n        subsets(nums, 0, sub, subs);\n        return subs;\n    }\nprivate:\n    void subsets(vector<int>& nums, int i, vector<int>& sub, vector<vector<int>>& subs) {\n        subs.push_back(sub);\n        for (int j = i; j < nums.size(); j++) {\n            if (j == i || nums[j] != nums[j - 1]) {\n                sub.push_back(nums[j]);\n                subsets(nums, j + 1, sub, subs);\n                sub.pop_back();\n            }\n        }\n    }\n};\n```\n\n**Iterative**\n\n```cpp\nclass Solution {\npublic:\n    vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n        sort(nums.begin(), nums.end());\n        vector<vector<int>> subs = {{}};\n        for (int i = 0, n = 0; i < nums.size(); i++) {\n            int j = !i || nums[i] != nums[i - 1] ? 0 : n;\n            n = subs.size();\n            for (; j < n; j++) {\n                subs.push_back(subs[j]);\n                subs.back().push_back(nums[i]);\n            }\n        }\n        return subs;\n    }\n};\n```
['Backtracking', 'Recursion', 'Iterator', 'C++']