Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 9390bfd

Browse files
update: 96
1 parent 0eaedc2 commit 9390bfd

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

‎README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ This is the solutions collection of my LeetCode submissions, most of them are pr
6060
| 91 | [Decode Ways](https://leetcode.com/problems/decode-ways/) | [JavaScript](./src/decode-ways/res.js) | Medium |
6161
| 93 | [Restore IP Addresses](https://leetcode.com/problems/restore-ip-addresses/) | [JavaScript](./src/restore-ip-addresses/res.js) | Medium |
6262
| 94 | [Binary Tree Inorder Traversal](https://leetcode.com/problems/binary-tree-inorder-traversal/) | [TypeScript](./src/binary-tree-inorder-traversal/res.ts) | Easy |
63+
| 96 | [unique-binary-search-trees](https://leetcode.com/problems/unique-binary-search-trees/) | [TypeScript](./src/unique-binary-search-trees/res.ts) | Medium |
6364
| 98 | [Validate Binary Search Tree](https://leetcode.com/problems/validate-binary-search-tree/) | [JavaScript](./src/validate-binary-search-tree/res.js) | Medium |
6465
| 100 | [Same Tree](https://leetcode.com/problems/same-tree/) | [JavaScript](./src/same-tree/res.js) | Easy |
6566
| 101 | [Symmetric Tree](https://leetcode.com/problems/symmetric-tree/) | [JavaScript](./src/symmetric-tree/res.js) | Easy |

‎src/unique-binary-search-trees/res.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
function numTrees(n: number): number {
2+
const calculateCache = new Array(n+1).fill(0);
3+
calculateCache[0] = 1;
4+
calculateCache[1] = 1;
5+
6+
for (let i=2; i<=n; i++) {
7+
for (let j = 0; j <= i-1; j++) {
8+
calculateCache[i] += calculateCache[i-j-1] * calculateCache[j];
9+
}
10+
}
11+
12+
return calculateCache[n];
13+
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /