(
List<List<Integer>> ans,
int start,
int[] nums,
List<Integer> list
)
| 11 | } |
| 12 | |
| 13 | public void helper( |
| 14 | List<List<Integer>> ans, |
| 15 | int start, |
| 16 | int[] nums, |
| 17 | List<Integer> list |
| 18 | ) { |
| 19 | if (start >= nums.length) { |
| 20 | ans.add(new ArrayList<>(list)); |
| 21 | } else { |
| 22 | // add the element and start the recursive call |
| 23 | list.add(nums[start]); |
| 24 | helper(ans, start + 1, nums, list); |
| 25 | // remove the element and do the backtracking call. |
| 26 | list.remove(list.size() - 1); |
| 27 | helper(ans, start + 1, nums, list); |
| 28 | } |
| 29 | } |
| 30 | } |