# Leetcode Subsets

dfs again!

class Solution {
public:
vector<vector<int> > subsets(vector<int> &S) {
ans.clear();
ans.push_back(v);
sort(S.begin(), S.end());
for(int i = 1; i <= S.size(); i++){
v.clear();
dfs(S, 0, 0, i);
}
return ans;
}
void dfs(vector<int> &S, int index, int cnt, int sum){
if(cnt == sum){
ans.push_back(v);
return ;
}
for(int i = index; i < S.size(); i++){
v.push_back(S[i]);
dfs(S, i+1, cnt+1, sum);
v.pop_back();
}
}
vector<int> v;
vector<vector<int> > ans;
};

• 本文已收录于以下专栏：

## Leetcode : Subsets II

URL：https://leetcode.com/problems/subsets-ii/#/description题目大意：Given a collection of integers that m...

## leetcode 90. Subsets II

Given a collection of integers that might contain duplicates, nums, return all possible subsets. ...

## 【leetcode】90. Subsets II

leetcode, subsets ||， 3种解法

## leetcode：暴力枚举法之Subsets II

leetcode：暴力枚举法之Subsets II 题目; Given a collection of integers that might contain duplicates, S, retur...

## LeetCode OJ:Subsets II

Subsets II   Given a collection of integers that might contain duplicates, S, return all possible...

## leetcode-78 Subsets

• sole_cc
• 2015年03月28日 19:19
• 378

Subsets I and II

## Subsets II -- leetcode

Given a collection of integers that might contain duplicates, S, return all possible subsets. Not...

## leetcode 90 Subsets II

leetcode 90 Subsets II c++ Python

## [LeetCode][Java] Subsets II

举报原因： 您举报文章：Leetcode Subsets 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)