标签:
1 class Solution { 2 public: 3 vector<vector<int>> subsets(vector<int>& nums) { 4 sort(nums.begin(), nums.end()); 5 vector<int> path; 6 vector<vector<int>> result; 7 subsets(nums, path, 0, result); 8 return result; 9 } 10 private: 11 void subsets(const vector<int>& nums, vector<int>& path, int step, vector<vector<int>>& result) { 12 if (step == nums.size()) { 13 result.push_back(path); 14 return; 15 } else { 16 // no current element 17 subsets(nums, path, step + 1, result); 18 // add current element 19 path.push_back(nums[step]); 20 subsets(nums, path, step + 1, result); 21 path.pop_back(); 22 } 23 } 24 };
标签:
原文地址:http://www.cnblogs.com/shadowwalker9/p/5780954.html