Skip to content

Commit be54fec

Browse files
authored
add js solution
1 parent e2d8c0a commit be54fec

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

problems/0096.不同的二叉搜索树.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,23 @@ func numTrees(n int)int{
211211
}
212212
```
213213

214+
Javascript:
215+
```Javascript
216+
const numTrees =(n) => {
217+
let dp = new Array(n+1).fill(0);
218+
dp[0] = 1;
219+
dp[1] = 1;
220+
221+
for(let i = 2; i <= n; i++) {
222+
for(let j = 1; j <= i; j++) {
223+
dp[i] += dp[j-1] * dp[i-j];
224+
}
225+
}
226+
227+
return dp[n];
228+
};
229+
```
230+
214231

215232

216233
-----------------------

0 commit comments

Comments
 (0)