My 8ms Solution


  • 0
    8

    The source is

    class Solution {

    public:

    void DFS(vector<vector<int> > &result,vector<int> &temp,map<int,int> & mymap,map<int,int>::iterator begin)
    {
        result.push_back(temp);
        for(map<int,int>::iterator it=begin;it!=mymap.end();it++)
        {
            if(it->second){
                temp.push_back(it->first);
                (it->second)--;
                DFS(result,temp,mymap,it);
                (it->second)++;
                temp.pop_back();
            }
        }
        return;
        
    }
    vector<vector<int>> subsetsWithDup(vector<int>& nums) {
        vector<vector<int> > result;
        if(nums.size()==0) return result;
        map<int,int> mymap;
        for(int i=0;i<nums.size();i++)
           mymap[nums[i]]++;
        vector<int> temp;
        DFS(result,temp,mymap,mymap.begin());
        return result;
    }
    

    };


Log in to reply
 

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