Best Solution
Approach\nUsing Recursion\n\n# Complexity\n- Time complexity:\nO(2^nk) --> k is average length of every subset\n\n- Space complexity:\nO(2^nk)\n\n# Code\n\nclas
# Approach\nUsing Recursion\n\n# Complexity\n- Time complexity:\n$$O(2^n*k)$$ --> k is average length of every subset\n\n- Space complexity:\n$$O(2^n*k)$$\n\n# Code\n```\nclass Solution {\npublic:    \n    void subsetHelper(int idx, vector<int>& nums, int n, vector<int> &temp, vector<vector<int>>& ans) {\n        ans.push_back(temp);\n        for (int i = idx; i < n; i++) {\n            if (i != idx && nums[i] == nums[i-1])\n                continue;\n            temp.push_back(nums[i]);\n            subsetHelper(i+1, nums, n, temp, ans);\n            temp.pop_back();\n        }\n    }\n\n    vector<vector<int>> subsetsWithDup(vector<int>& nums) {\n        int n = nums.size();\n        vector<vector<int>> ans;\n        vector<int> temp;\n        sort(nums.begin(), nums.end());\n        subsetHelper(0, nums, n, temp, ans);\n        return ans;\n    } \n};\n```
['C++']