public class Solution {
public List<List<Integer>> subsets(int[] nums) {
List<List<Integer>> result = new ArrayList<>();
if (nums == null || nums.length == 0) {
return result;
}
helper(result, new ArrayList<Integer>(), nums, 0);
return result;
}
private void helper(List<List<Integer>> result, List<Integer> path, int[] nums, int start) {
result.add(new ArrayList<>(path));
for (int i = start; i < nums.length; i++) {
path.add(nums[i]);
helper(result, path, nums, i + 1);
path.remove(path.size() - 1);
}
}
}
2016年7月15日星期五
[LeetCode] #78 Subsets
订阅:
博文评论 (Atom)
没有评论:
发表评论