二刷78. Subsets

Medium
应该可以秒的,但是i+1那里一开始写成了index+1

class Solution {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        List<Integer> list = new ArrayList<>();
        dfsHelper(res, list, nums, 0);
        return res;    
    }

    private void dfsHelper(List<List<Integer>> res, List<Integer> list, int[] nums, int index){
        res.add(new ArrayList<Integer>(list));
        for(int i = index; i < nums.length; i++){
            if (list.contains(nums[i])){
                continue;
            }
            list.add(nums[i]);
            dfsHelper(res, list, nums, i + 1);
            list.remove(list.size() - 1);
        }
    }
}
    原文作者:greatfulltime
    原文地址: https://www.jianshu.com/p/6ffd9a5b20d4
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞