您的位置:首页 > 其它

[LeetCode]78 Subsets

2015-01-04 15:40 585 查看
https://oj.leetcode.com/problems/subsets/
http://blog.csdn.net/linhuanmars/article/details/24286377
public class Solution {
public List<List<Integer>> subsets(int[] S) {

Arrays.sort(S);

List<List<Integer>> results = new ArrayList<>();
help(S, 0, new ArrayList<Integer>(), results);
return results;
}

private void help(int[] S, int start, List<Integer> items, List<List<Integer>> results)
{
if (items.size() <= S.length)
{
results.add(new ArrayList<Integer>(items));
}

if (items.size() == S.length)
return;

for (int i = start ; i < S.length ; i ++)
{
items.add(S[i]);

help(S, i + 1, items, results);

items.remove(items.size() - 1);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  LeetCode Permutations NP