码迷,mamicode.com
首页 > 其他好文 > 详细

78. Subsets

时间:2016-08-17 18:03:56      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:

 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 };

 

78. Subsets

标签:

原文地址:http://www.cnblogs.com/shadowwalker9/p/5780954.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!