Subsets II

来源:互联网 发布:淘宝模特室内怎么布光 编辑:程序博客网 时间:2024/05/19 21:41
public class Solution {    public List<List<Integer>> subsetsWithDup(int[] nums) {        List<List<Integer>> res = new LinkedList<>();        if (nums == null || nums.length == 0) {            return res;        }        Arrays.sort(nums);        List<Integer> list = new LinkedList<>();        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);        }    }}

0 0
原创粉丝点击