# 96. Unique Binary Search Trees

`Input: n = 3Output: 5`
`Input: n = 1Output: 1`
• `1 <= n <= 19`
• number of unique BST for a tree with n=1 is 1
• number of unique BST for a tree with n=2 is 2
• number of unique BST for a tree with n=3 is
`class Solution(object):    def numTrees(self, n):        dp=[0 for i in range(n+2)]        dp[0]=1        dp[1]=1        dp[2]=2        for i in range(2,n+1):            sum_=0            for j in range(0,i):                m,k=j,i-1-j                    sum_+=dp[m]*dp[k]            dp[i]=sum_        return dp[n]`
`class Solution(object):    def numTrees(self, n):        return(math.factorial(2*n)/(math.factorial(n)*math.factorial(n+1)))`

--

--

--

## More from Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.

Love podcasts or audiobooks? Learn on the go with our new app.

## Dhanarajappu

Tech-Enthusiast, Coder,Explorer,Geeky,Software Engineer |A piece of code delivers everything that you need. The world is all about codes.