[leetcode 78] Subsets
2015-01-11 14:22
232 查看
Given a set of distinct integers, S, 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 S =
Note:
Elements in a subset must be in non-descending order.
The solution set must not contain duplicate subsets.
For example,
If S =
[1,2,3], a solution is:
[ [3], [1], [2], [1,2,3], [1,3], [2,3], [1,2], [] ]
class Solution { public: vector<vector<int> > subsets(vector<int> &S) { sort(S.begin(), S.end()); vector<vector<int> > res; vector<int> path; dfs(S, 0, path, res); return res; } void dfs(const vector<int> &s, int start, vector<int> &path, vector<vector<int> > &res) { if (start == s.size()) { res.push_back(path); return ; } for (int i = start; i < s.size(); i++) { //dfs(s, i+1, path, res); path.push_back(s[i]); dfs(s, i+1, path, res); path.pop_back(); } res.push_back(path); return ; } };
相关文章推荐
- leetcode_middle_58_78. Subsets
- leetcode_77_combiantion_78_subsets_90_subsets2
- (LeetCode 78)SubSets
- LeetCode 78. Subsets
- LeetCode(78) Subsets
- <LeetCode OJ> 78 / 90 Subsets (I / II)
- leetcode: 78. Subsets
- LeetCode(78) Subsets
- LeetCode78 Subsets
- Leetcode 78. Subsets
- Leetcode 78 Subsets
- 【LeetCode】78_Subsets
- LeetCode 78 Subsets
- [leetcode]78. Subsets
- LeetCode 78. Subsets
- LeetCode 78 Subsets
- Leetcode 78. Subsets & 90. Subsets II
- Leetcode 78. Subsets
- LeetCode 78. Subsets
- Leetcode 78 Subsets