原题
https://leetcode.com/problems/unique-binary-search-trees/
Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?
思路
对于n个值,以i为根,则可以将[1,i-1]放入左边,[i+1,n]放入右边,因此有[i-1]*[i-j]种方式。
代码
1 | class Solution: |
https://leetcode.com/problems/unique-binary-search-trees/
Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?
对于n个值,以i为根,则可以将[1,i-1]放入左边,[i+1,n]放入右边,因此有[i-1]*[i-j]种方式。
1 | class Solution: |
Update your browser to view this website correctly. Update my browser now