binary tree solutions

  • 0
        public static List<List<Integer>> subsets(int[] nums) {
            List<List<Integer>> subsets = new ArrayList<>();
            subsets(subsets, new ArrayList<Integer>(), nums, 0);
            return subsets;
        public static void subsets(List<List<Integer>> subsets, List<Integer> subset, int[] nums, int k) {
            if (k == nums.length - 1) {
                List<Integer> l1 = new ArrayList<>(subset);
                List<Integer> l2 = new ArrayList<>(subset);
                subsets.add(l1);    subsets.add(l2);
            List<Integer> temp = new ArrayList<>(subset);
            List<Integer> temp1 = new ArrayList<>(subset);
            subsets(subsets, temp, nums, k+1);
            subsets(subsets, temp1, nums, k+1);

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.