| 5 | } |
| 6 | |
| 7 | private void helper(int start, int[] nums, List<List<Integer>> result) |
| 8 | { |
| 9 | if(start==nums.length-1){ |
| 10 | ArrayList<Integer> list = new ArrayList<>(); //if starting value(say n) is the last value , this will make a new list with the values and the new starting value is n |
| 11 | for(int num: nums) |
| 12 | { |
| 13 | list.add(num); |
| 14 | } |
| 15 | result.add(list); |
| 16 | return; |
| 17 | } |
| 18 | |
| 19 | for(int i=start; i<nums.length; i++) //a loop to keep on swapping as many times as there are values in the list |
| 20 | { |
| 21 | swap(nums, i, start); |
| 22 | helper(start+1, nums, result); |
| 23 | swap(nums, i, start); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | private void swap(int[] nums, int i, int j) |
| 28 | { |