@@ -0,0 +1,1451 @@
+/***%0A * Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.%0A *%0A * For example,%0A * Given n = 3, your program should return all 5 unique BST's shown below.%0A *%0A *    1         3     3      2      1%0A *     %5C       /     /      / %5C      %5C%0A *      3     2     1      1   3      2%0A *     /     /       %5C                 %5C%0A *    2     1         2                 3%0A */%0A/**%0A * Definition for binary tree%0A * public class TreeNode %7B%0A *     int val;%0A *     TreeNode left;%0A *     TreeNode right;%0A *     TreeNode(int x) %7B val = x; left = null; right = null; %7D%0A * %7D%0A */%0Aimport java.util.List;%0Aimport java.util.ArrayList;%0A%0Apublic class Solution %7B%0A    public List%3CTreeNode%3E generateTrees(int n) %7B%0A        return generate(1, n);%0A    %7D%0A    private List%3CTreeNode%3E generate(int start, int end) %7B%0A        List%3CTreeNode%3E subtree = new ArrayList%3CTreeNode%3E();%0A        if (start %3E end) %7B%0A            subtree.add(null);%0A            return subtree;%0A        %7D%0A        for (int k = start; k %3C= end; k++) %7B%0A            List%3CTreeNode%3E leftSubs = generate(start, k - 1);%0A            List%3CTreeNode%3E rightSubs = generate(k + 1, end);%0A            for (TreeNode i : leftSubs)%0A                for (TreeNode j: rightSubs) %7B%0A                    TreeNode node = new TreeNode(k);%0A                    node.left = i;%0A                    node.right = j;%0A                    subtree.add(node);%0A                %7D%0A        %7D%0A        return subtree;%0A    %7D%0A%7D%0A

add UniqueBinarySearchTreesII.java