Easy C++


  • 0
    S

    class Solution {
    public:
    vector<vector<int>> subsetsWithDup(vector<int>& nums) {
    sort(nums.begin(),nums.end());
    vector<int>current;
    vector<vector<int>>res;
    DFS(nums,current,res,0);
    return res;
    }
    public:
    void DFS(vector<int>& nums, vector<int>& current, vector<vector<int>>& res, int index){
    if(index == nums.size()){
    if(std::find(res.begin(),res.end(),current)==res.end()){
    res.push_back(current);
    }
    return;
    }
    current.push_back(nums[index]);
    DFS(nums,current,res,index+1);
    current.pop_back();
    DFS(nums, current, res, index+1);
    }
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.