Given an integer n, generate all structurally unique BST’s (binary search trees) that store values 1 … n.
Example
Input: 3
Output:
1 | [ |
Explanation:
The above output corresponds to the 5 unique BST’s shown below:
1 | 1 3 3 2 1 |
Code
1 | public class TreeNode { |
1 | public List<TreeNode> generateTrees(int n) { |