QUESTIONGiven an integern, returnthe number of structurally uniqueBST's (binary search trees) which has exactlynnodes of unique values from1ton.Input: n = 3
Output: 5ALGRITHOMBy solving this problem recursively we can utilize the code 1's thought, however, it will be a time limit exceeded.Let's turn our vision to another way.A key insight here is that you need to realize that the content doesn't matter, the number is what we are utilizing.We loop each node and regard it as the root, and at that point, the result would be its left unique BST tree count plus its right unique BST count. So we lo
...
继续阅读
(36)