标签:
Given a collection of integers that might contain duplicates, nums, return all possible subsets.
Note: The solution set must not contain duplicate subsets.
For example,
If nums = [1,2,2]
, a solution
is:
[ [2], [1], [1,2,2], [2,2], [1,2], [] ]
Subscribe to see which companies asked this question
c++ code:
class Solution { public: vector<vector<int>> subsets(vector<int>& nums) { vector<vector<int>> combs; vector<int> comb; combine(combs, comb, nums, 0); return combs; } // 自定义函数 void combine(vector<vector<int>> &combs, vector<int> &comb,vector<int>& nums,int begin) { combs.push_back(comb); for(int i=begin;i<nums.size();i++) { comb.push_back(nums[i]); combine(combs,comb,nums,i+1); comb.pop_back(); } } };
标签:
原文地址:http://blog.csdn.net/itismelzp/article/details/51627541