add: 不同的二叉搜索树

This commit is contained in:
yi-ge 2020-07-15 12:23:07 +08:00
parent 2e60e7aa98
commit 20f821a921
4 changed files with 33 additions and 1 deletions

13
.vscode/settings.json vendored
View File

@ -36,5 +36,16 @@
"zhan",
"zhong",
"zhuan"
]
],
"standard.options": {
"globals": [
"$",
"jQuery",
"fetch"
],
"usePackageJson": true,
"env": {
"jest": true
}
}
}

View File

@ -516,6 +516,10 @@ LeetCode 与 LintCode 解题记录。此为个人练习仓库,代码中对重
- LeetCode 108. 将有序数组转换为二叉搜索树 <https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/>
- LintCode 106. 有序链表转换为二叉搜索树 <https://www.lintcode.com/problem/convert-sorted-list-to-binary-search-tree/description>
- [不同的二叉搜索树](src/tree/unique-binary-search-trees.js)
- LeetCode 96. 不同的二叉搜索树 <https://leetcode-cn.com/problems/unique-binary-search-trees/>
## 链表
- [合并 K 个排序链表](src/list/merge-k-sorted-lists.js)

View File

@ -0,0 +1,12 @@
// 卡塔兰数
/**
* @param {number} n
* @return {number}
*/
export const numTrees = function (n) {
let C = 1
for (let i = 0; i < n; ++i) {
C = C * 2 * (2 * i + 1) / (i + 2)
}
return C
}

View File

@ -0,0 +1,5 @@
import { numTrees } from '../../src/tree/unique-binary-search-trees'
test('不同的二叉搜索树', () => {
expect(numTrees(3)).toBe(5)
})