96-unique-binary-search-trees

DevGod
Vtuber
/** * @param {number} n * @return {number} */
var memo = [1,1,2,5,14,42]var numTreesOld = function(n) { if(memo[n] !== undefined){ return memo[n]; }
let result = 0; for (let i = 0; i < n; i++) { result += numTrees(i) * numTrees(n - i - 1); }
memo[n] = result; return memo[n];};
//Very fastvar numTreesOld = function(n) {
}
class Solution: def numTrees(self, n: int) -> int: return comb(2 * n, n) // (n + 1)