mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 16:54:50 +08:00
add js solution
This commit is contained in:
@ -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];
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-----------------------
|
-----------------------
|
||||||
|
Reference in New Issue
Block a user