public class Solution {
//http://www.1point3acres.com/bbs/forum.php?mod=viewthread&tid=135214&extra=page%3D9%26filter%3Dsortid%26sortid%3D311%26searchoption%5B3046%5D%5Bvalue%5D%3D2%26searchoption%5B3046%5D%5Btype%5D%3Dradio%26sortid%3D311
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> res = new LinkedList<>();
if (nums == null || nums.length == 0) {
return res;
}
List<Integer> list = new LinkedList<>();
helper(res, nums, list, 0);
return res;
}
private void helper(List<List<Integer>> res, int[] nums, List<Integer> list, int pos) {
res.add(new LinkedList<>(list));
for (int i = pos; i < nums.length; i++) {
list.add(nums[i]);
helper(res, nums, list, i + 1);
list.remove(list.size() - 1);
}
}
}
Subsets
最新推荐文章于 2019-06-11 10:20:00 发布