您的位置:首页 > 其它

Subsets II

2016-07-10 20:48 169 查看
public class Solution {
public List<List<Integer>> subsetsWithDup(int[] nums) {
List<List<Integer>> res = new LinkedList<>();
if (nums == null || nums.length == 0) {
return res;
}
List<Integer> list = new LinkedList<>();
Arrays.sort(nums);
helper(res, list, nums, 0);
return res;
}

private void helper(List<List<Integer>> res, List<Integer> list, int[] nums, int pos) {
res.add(new LinkedList<>(list));
for (int i = pos; i < nums.length; i++) {
if (i != pos && nums[i] == nums[i - 1]) {
continue;
}
list.add(nums[i]);
helper(res, list, nums, i + 1);
list.remove(list.size() - 1);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: