about // doc

LeetCode - Unique Binary Search Tree (I and II)

Click here to go back to LeetCode summary page.

Problem description is here, or as follows:

Given n, how many structurally unique BST's (binary 
search trees) that store values 1...n?

For example,
Given n = 3, there are a total of 5 unique BST's.

   1         3     3      2      1
    \       /     /      / \      \
     3     2     1      1   3      2
    /     /       \                 \
   2     1         2                 3

A follow-up on this problem is here, that is, to generate all unique BSTs.

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

For example,
Given n = 3, your program should return all 5 unique BST's shown below.

   1         3     3      2      1
    \       /     /      / \      \
     3     2     1      1   3      2
    /     /       \                 \
   2     1         2                 3
comments powered by Disqus