Compare commits

...

6 Commits

7 changed files with 48 additions and 23 deletions

View File

@ -5,18 +5,17 @@ name: Node.js CI
on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x]
node-version: [12.x, 14.x]
steps:
- uses: actions/checkout@v2

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

@ -1,10 +1,4 @@
/**
* Definition for a binary tree node.
*/
function TreeNode(val) {
this.val = val
this.left = this.right = null
}
import TreeNode from '../../test/tree/TreeNode'
/**
* @param {number[]} nums

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

@ -1,5 +1,5 @@
import { sortedArrayToBST } from '../../src/tree/convert-sorted-array-to-binary-search-tree.js'
test('将有序数组转换为二叉搜索树', () => {
expect(sortedArrayToBST()).toEqual()
expect(sortedArrayToBST([-10, -3, 0, 5, 9])).toEqual({ left: { left: null, right: { left: null, right: null, val: -3 }, val: -10 }, right: { left: null, right: { left: null, right: null, val: 9 }, val: 5 }, val: 0 })
})

View File

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