78. Subsets

class Solution {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res=new ArrayList<List<Integer>>();
        subsets(0, new ArrayList<Integer>(), res, nums);
        return res;
    }
    private void subsets(int idx, List<Integer> list, List<List<Integer>> res, int[] nums){
        if(idx==nums.length)
        {
            res.add(new ArrayList<Integer>(list));
            return;
        }
        subsets(idx+1, list, res, nums);
        list.add(nums[idx]);
        subsets(idx+1, list, res, nums);
        list.remove(list.size()-1);
    }
}

 

posted @ 2017-09-27 05:02  Weiyu Wang  阅读(164)  评论(0编辑  收藏  举报