LeetCode 90. Subsets II

2019-12-16 18:06:49 浏览数 (1)

题目

dfs

代码语言:javascript复制
class Solution {
public:
    vector<vector<int>> ans;
    vector<int> res;
    vector<vector<int>> subsetsWithDup(vector<int>& nums) {
        
        sort(nums.begin(),nums.end());
       
        fun(nums,0);
        
        return ans;
        
    }
    
    void fun(vector<int>& nums,int x)
    {
        ans.push_back(res);
        for(int i=x;i<nums.size();i  )
        {
            if(i!=x&&nums[i]==nums[i-1])
            {
                continue;
            }
            
            res.push_back(nums[i]);
            fun(nums,i 1);
            res.pop_back();
        }
    }
};
dfs

0 人点赞