@@ -0,0 +1,1255 @@
+// 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/**%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 */%0Apublic class Solution %7B%0A    public List%3CTreeNode%3E generateTrees(int n) %7B%0A    %09return helper(1, n);%0A    %7D%0A%0A    public List%3CTreeNode%3E helper(int start, int end)%7B%0A    %09List%3CTreeNode%3E list = new ArrayList%3CTreeNode%3E();%0A%0A    %09if(start %3E end)%7B%0A    %09%09list.add(null);%0A    %09%09return list;%0A    %09%7D%0A%0A    %09for(int i = start; i %3C= end; i++)%7B%0A    %09%09List%3CTreeNode%3E lefts = helper(start, i - 1);%0A    %09%09List%3CTreeNode%3E rights = helper(i + 1, end);%0A    %09%09for(TreeNode left : lefts)%7B%0A    %09%09%09for(TreeNode right : rights)%7B%0A    %09%09%09%09TreeNode node = new TreeNode(i);%0A    %09%09%09%09node.left = left;%0A    %09%09%09%09node.right = right;%0A    %09%09%09%09list.add(node);%0A    %09%09%09%7D%0A    %09%09%7D%0A    %09%7D%0A%0A    %09return list;%0A    %7D%0A%7D%0A

add unique binary search tree ii solution