题目:
Given a collection of integers that might contain duplicates, nums, return all possible subsets (the power set).
Note: The solution set must not contain duplicate subsets.
Example:
Input: [1,2,2]
Output:
[
[2],
[1],
[1,2,2],
[2,2],
[1,2],
[]
]
解法1:
回溯法
首先对数据进行排序然后
用
if(i > start && nums[i] == nums[i-1]) continue;
去重
c++:
class Solution {
public:
vector<vector<int>> subsetsWithDup(vector<int>& nums) {
vector<vector<int>> res;
vector<int> path;
sort(nums.begin(),nums.end());
DFS(nums, path, res, 0);
return res;
}