Unique Binary Search Trees *
1 3 3 2 1
\ / / / \ \
3 2 1 1 3 2
/ / \ \
2 1 2 3 F\[1\] \* F\[0\] when root is 2 then left contains 1 digits and right is null so.class Solution(object):
def numTrees(self, n):
if n <= 0:
return 0
F = [0] * (n + 1)
F[0] = 1
F[1] = 1
for i in range(2, n + 1):
for j in range(0, i):
F[i] += F[j] * F[i - j - 1]
return F[n]Last updated