I am running a Java program in IntelliJ, it includes an recursion, and I have no idea how it works. Also I desire to see what the output of each step of recursion is. How can I check that with debugger.
Thank you guys, here is what I have.
//Given a set of distinct integers, nums, return all possible subsets.
public List<List<Integer>> subsets(int[] num) {
List<List<Integer>> result = new ArrayList<>();
if(num == null || num.length == 0) {
return result;
}
List<Integer> list = new ArrayList<Integer>();
Arrays.sort(num);
subsetsHelper(result, list, num, 0);
return result;
}
private void subsetsHelper(List<List<Integer>> result,
List<Integer> list, int[] num, int pos) {
result.add(new ArrayList<Integer>(list));
for (int i = pos; i < num.length; i++) {
list.add(num[i]);
subsetsHelper(result, list, num, i + 1);
list.remove(list.size() - 1);
}
}
public static void main(String[] args){
Subset_I test = new Subset_I();
System.out.println(test.subsets(new int[] {0,1}));
}