How Far Have You Gotten in Leet — (4)
1 min readDec 31, 2020
Description
Explanation
- BST has two leaves on every single level, in which the left side is always smaller and the right bigger than its root node.
- When N is k, the value of the root node could be 1 to k and one or more numbers on each side make diverse sub-trees.
- The number of trees of a root node is multiplying the number of sub-trees on the left and on the right.
- Getting a total combination of n is to sum up all the number of trees created in each root node.
Solution
Review
Afraid of the BST. Thought that it was a sort of a combination of graph and DP, which felt so hard at first. Once I figured out the rule of BST, it did not take long to find the way to get the number of trees. One reminder: DP is to memorize each step’s result that comes out according to a general rule.