-2

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}));
}
Software Engineer
  • 15,457
  • 7
  • 74
  • 102
Mingya Ma
  • 7
  • 1
  • 2

1 Answers1

0

You can add a breakpoint in the code and then debug it.

The other alternative is to print out the values using System.out.println() and view the values in the console.

Joyson
  • 3,025
  • 1
  • 20
  • 34