My easy C++ code for recursive solution with 10 lines,8ms.

  • 0
    vector<vector<int>> subsets(vector<int>& nums) 
    	sort(nums.begin(), nums.end());
    	int sz = nums.size();
    	if (sz < 1)return vector<vector<int>>(1, nums);
    	int temp = nums[0];
    	vector<vector<int>>res = subsets(nums);
    	for (vector<vector<int>>::size_type it = 0; it != res.size(); it++)
    		res[it].insert(res[it].begin(), temp);
    	copy(res.begin(), res.end(), inserter(fin, fin.begin()));
    	return fin;

Log in to reply

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