8ms c++


  • 0
    B
    class Solution {
    public:
        vector< vector<int> > ans;
        vector<int> tmp;
        vector< vector<int> > subsets(vector<int>& nums) {
            sort(nums.begin(),nums.end());
            depthSearch(0,nums,nums.size());
            return ans;
        }
        void depthSearch(int index,vector<int>& nums,int n)
        {
            if (index==n)
            {
                ans.push_back(tmp);
                return ;
            }
            tmp.push_back(nums[index]);
            depthSearch(index+1,nums,n);
            tmp.pop_back();
            depthSearch(index+1,nums,n);
        }
    };
    

Log in to reply
 

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