<p>Given an integer <code>n</code>, return <em>the number of structurally unique <strong>BST&#39;</strong>s (binary search trees) which has exactly </em><code>n</code><em> nodes of unique values from</em> <code>1</code> <em>to</em> <code>n</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<img alt="" src="https://assets.leetcode.com/uploads/2021/01/18/uniquebstn3.jpg" style="width: 600px; height: 148px;" />
<pre>
<strong>Input:</strong> n = 3
<strong>Output:</strong> 5
</pre>

<p><strong class="example">Example 2:</strong></p>

<pre>
<strong>Input:</strong> n = 1
<strong>Output:</strong> 1
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>1 &lt;= n &lt;= 19</code></li>
</ul>

class Solution:

    def numTrees(self, n: int) -> int:
        global memo
        memo = [[0 for i in range(n+1)] for j in range(n+1)]
        return self.count(1, n)
        
    def count(self, lo, hi):
        if lo > hi:
            return 1
        if memo[lo][hi] != 0:
            return memo[lo][hi]

        res = 0
        for i in range(lo, hi+1):
            left = self.count(lo, i - 1)
            right = self.count(i + 1, hi)
            res += left * right
        memo[lo][hi] = res

        return res
16100