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

78. Subsets

时间:2017-08-28 00:54:35      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:tor   int   ott   http   method   dup   convert   duplicate   chosen   

Given a set of distinct integers, nums, return all possible subsets.

Note: The solution set must not contain duplicate subsets.

For example,
If nums = [1,2,3], a solution is:

[
  [3],
  [1],
  [2],
  [1,2,3],
  [1,3],
  [2,3],
  [1,2],
  []
]

 


 
class Solution {
public:
   
    void subset(vector<vector<int>>& result,vector<int>&path,int step,vector<int>&nums)
    {
        if(nums.size() == step)
        {
            result.push_back(path);
            return;
        }
       
        subset(result,path,step+1,nums);
        path.push_back(nums[step]);
        subset(result,path,step+1,nums);
        path.pop_back();
    }
   
   
    vector<vector<int>> subsets(vector<int>& nums) {
        vector<vector<int>> result;
        if(nums.size() == 0)
        {
            return result;
        }
       
        vector<int> path;
        subset(result,path,0,nums);
        
        return result;
       
    }
};

78. Subsets

标签:tor   int   ott   http   method   dup   convert   duplicate   chosen   

原文地址:http://www.cnblogs.com/Biao-Coding/p/7440905.html

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