add js solution

This commit is contained in:
Qi Jia
2021-07-03 20:38:53 -07:00
committed by GitHub
parent e2d8c0a1cd
commit be54fec1dd

View File

@ -211,6 +211,23 @@ func numTrees(n int)int{
} }
``` ```
Javascript
```Javascript
const numTrees =(n) => {
let dp = new Array(n+1).fill(0);
dp[0] = 1;
dp[1] = 1;
for(let i = 2; i <= n; i++) {
for(let j = 1; j <= i; j++) {
dp[i] += dp[j-1] * dp[i-j];
}
}
return dp[n];
};
```
----------------------- -----------------------