Simple DFS Java solution beating 98%

  • 0

    public class Solution {

    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<List<Integer>>();
        ArrayList<Integer> list = new ArrayList<Integer>();
        helper(nums, 0, list, res);
        return res;
    private void helper(int[] nums, int idx, ArrayList<Integer> list, List<List<Integer>> res){
        for(int i=idx;i<nums.length;i++){
            ArrayList<Integer> _list = (ArrayList)list.clone();
            helper(nums, i+1, _list, res);


Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.