Unique Binary Search Trees II

Given n, generate all structurally unique BST's (binary search trees) that store values 1, ... , n.

Solution:

The idea is exactly the same with Unique Binary Search Trees.

Notes: we need to use TreeNode *root = new TreeNode(i) to initialize a new struct and pointer.

The following code passes LeetCode online large judge.

Comments

Popular posts from this blog

Maximum Gap

[ITint5] Maximum Subarray for a Circular Array

[CC150] Chapter 8 Object-Oriented Design