import java.util.ArrayList;
import java.util.List;

/**
 * Created by drfish on 27/05/2017.
 */
public class _095UniqueBinarySearchTreesII {
    public List<TreeNode> generateTrees(int n) {
        List<TreeNode> result = genTrees(1, n);
        if (result.get(0) == null) {
            return new ArrayList<>();
        } else {
            return result;
        }
    }

    private List<TreeNode> genTrees(int start, int end) {
        List<TreeNode> result = new ArrayList<>();
        if (start > end) {
            result.add(null);
        }
        for (int i = start; i <= end; i++) {
            List<TreeNode> leftTrees = genTrees(start, i - 1);
            List<TreeNode> rightTrees = genTrees(i + 1, end);
            for (TreeNode leftTree : leftTrees) {
                for (TreeNode rightTree : rightTrees) {
                    TreeNode root = new TreeNode(i);
                    root.left = leftTree;
                    root.right = rightTree;
                    result.add(root);
                }
            }
        }
        return result;
    }
}

@@ -49,16 +49,422 @@
 t;%0A%0A/**%0A
+ * Given an integer n, generate all structurally unique BST's (binary search trees) that store values 1...n.%0A * %3Cp%3E%0A * For example,%0A * Given n = 3, your program should return all 5 unique BST's shown below.%0A * %3Cp%3E%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 * %3Cp%3E%0A
  * Creat

Add description for java 95