1# Runtime: 58 ms (Top 20.54%) | Memory: 13.9 MB (Top 13.32%)2class Solution(object):3def numTrees(self, n):4if n == 0 or n == 1:5return 16# Create 'sol' array of length n+1...7sol = [0] * (n + 1)8# The value of the first index will be 1.9sol[0] = 110# Run a loop from 1 to n+1...11for i in range(1, n + 1):12# Within the above loop, run a nested loop from 0 to i...13for j in range(i):14# Update the i-th position of the array by adding the multiplication of the respective index...15sol[i] += sol[j] * sol[i - j - 1]16# Return the value of the nth index of the array to get the solution...17return sol[n]