[Java] Two Way of Recursive thinking
1) Each recursion level focuses on all the following elements. We scan through all the following elements and decide whether to choose or not choose that elemen
1) Each recursion level focuses on all the following elements. We scan through all the following elements and decide whether to choose or not choose that element. (Every level split into N branches.)\n```java\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        Arrays.sort(nums);\n        List<List<Integer>> res = new ArrayList<>();\n        helper(res,new ArrayList<>(),nums,0);\n        return res;\n    }\n    \n    public void helper(List<List<Integer>> res, List<Integer> ls, int[] nums, int pos) {\n        res.add(new ArrayList<>(ls));\n        for(int i=pos;i<nums.length;i++) {\n            if(i>pos&&nums[i]==nums[i-1]) continue;\n            ls.add(nums[i]);\n            helper(res,ls,nums,i+1);     \n            ls.remove(ls.size()-1);\n        }\n    }\n}\n```\n2) Each recursion level focuses on one element, we need to decide choose or not choose this element. (Every level split into 2 branches.)\n```java\nclass Solution {\n    public List<List<Integer>> subsetsWithDup(int[] nums) {\n        Arrays.sort(nums);\n        List<List<Integer>> res = new ArrayList<>();\n        helper(res,new ArrayList<>(),nums,0,false);\n        return res;\n    }\n    \n    public void helper(List<List<Integer>> res, List<Integer> ls, int[] nums, int pos, boolean choosePre) {\n        if(pos==nums.length) {\n            res.add(new ArrayList<>(ls));\n            return;\n        }\n        helper(res,ls,nums,pos+1,false);\n        if(pos>=1&&nums[pos]==nums[pos-1]&&!choosePre) return;\n        ls.add(nums[pos]);\n        helper(res,ls,nums,pos+1,true);\n        ls.remove(ls.size()-1);\n    }\n}\n```
[]