import java.util.*;

public class Solution {
    public ArrayList<ArrayList<Integer>> subsets(int[] nums) {
        ArrayList<ArrayList<Integer>> ans = new ArrayList<>();
        process(nums, 0, ans, new LinkedList<>());
        return ans;
    }

    public static void process(int[] nums, int index, ArrayList<ArrayList<Integer>> ans,
                               LinkedList<Integer> list) {
        if (index == nums.length) {
            ans.add(new ArrayList<>(list));
            return;
        }
        process(nums, index + 1, ans, list);
        list.add(nums[index]);
        process(nums, index + 1, ans, list);
        list.removeLast();
    }
}