human
Write me a code to number of Unique BST with a given key and the other steps required given the following:
Number of Unique BST with a given key | Dynamic Programming | Function to find number of unique BST.
DP to store the number of unique BST with key i.
Base case.
fill the dp table in top - down approach ..
n - i in right * i - 1 in left.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to number of Unique BST with a given key and the other steps required.
 def numberOfBST ( n ) :
	dp = [ 0 ] * ( n + 1 )
	dp [ 0 ] , dp [ 1 ] = 1 , 1
	for i in range ( 2 , n + 1 ) :
		for j in range ( 1 , i + 1 ) :
			dp [ i ] = dp [ i ] + ( dp [ i - j ] * dp [ j - 1 ] )
	return dp [ n ]
if __name__ == " _ _ main _ _ " :
	n = 3
	print ( " Number ▁ of ▁ structurally ▁ Unique ▁ BST ▁ with " , n , " keys ▁ are ▁ : " , numberOfBST ( n ) )