###### Subsets

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

Note:

• Elements in a subset must be in non-descending order.
• 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 int_to_bool(int n,vector<int>&index)
{
int len=index.size();
index.clear();
index.resize(len);
int i=0;
while(n)
{
int temp=n%2;
index[i]=temp;
i++;
n/=2;
}
}
vector<vector<int>> subsets(vector<int>& nums) {
vector<vector<int>> res;
if(nums.size()==0) return res;
sort(nums.begin(),nums.end());
int len=nums.size();
int max=(1<<nums.size());
vector<int> index(len,0);
for(int i=0;i<max;i++)
{
int_to_bool(i,index);
vector<int> temp;
for(int j=0;j<len;j++)
{
if(index[j]==1)
temp.push_back(nums[j]);
}
res.push_back(temp);
}
return res;
}
};

#### LeetCode Subsets 和 LeetCode Subsets II

2014-04-09 22:02:48

#### leetcode 78. Subsets-数组子集|回溯算法

2016-06-07 17:04:45

#### 【LeetCode with Python】 Subsets II

2014-07-04 16:11:45

#### leetcode解题之 77. Combinations&78. Subsets&90. Subsets II java 版（求所有子集）

2017-04-08 19:36:52

#### 698. Partition to K Equal Sum Subsets

2017-10-15 11:36:26

#### LeetCode 之 Subsets（图和暴力枚举）

2015-07-29 11:15:59

#### LeetCode OJ 系列之78 Subsets --Python

2015-11-18 22:07:50

#### Subsets -- LeetCode

2014-04-22 08:08:48

#### 回溯法——subsets、subsets-ii数字数组的所有组合

2016-05-28 20:09:27

#### [C++]LeetCode: 64 Subsets II

2014-12-31 12:52:02

Subsets