Compare commits
6 Commits
450f1f6b5d
...
master
Author | SHA1 | Date | |
---|---|---|---|
20f821a921 | |||
2e60e7aa98 | |||
69986d68fd | |||
7f6439ce7c | |||
41aa639602 | |||
146b33a651 |
27
.github/workflows/nodejs.yml
vendored
27
.github/workflows/nodejs.yml
vendored
@ -5,27 +5,26 @@ name: Node.js CI
|
|||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
pull_request:
|
pull_request:
|
||||||
branches: [ master ]
|
branches: [master]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
node-version: [10.x, 12.x]
|
node-version: [12.x, 14.x]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Use Node.js ${{ matrix.node-version }}
|
- name: Use Node.js ${{ matrix.node-version }}
|
||||||
uses: actions/setup-node@v1
|
uses: actions/setup-node@v1
|
||||||
with:
|
with:
|
||||||
node-version: ${{ matrix.node-version }}
|
node-version: ${{ matrix.node-version }}
|
||||||
- run: npm install -g yarn
|
- run: npm install -g yarn
|
||||||
- run: yarn install
|
- run: yarn install
|
||||||
- run: yarn test
|
- run: yarn test
|
||||||
env:
|
env:
|
||||||
CI: true
|
CI: true
|
||||||
|
13
.vscode/settings.json
vendored
13
.vscode/settings.json
vendored
@ -36,5 +36,16 @@
|
|||||||
"zhan",
|
"zhan",
|
||||||
"zhong",
|
"zhong",
|
||||||
"zhuan"
|
"zhuan"
|
||||||
]
|
],
|
||||||
|
"standard.options": {
|
||||||
|
"globals": [
|
||||||
|
"$",
|
||||||
|
"jQuery",
|
||||||
|
"fetch"
|
||||||
|
],
|
||||||
|
"usePackageJson": true,
|
||||||
|
"env": {
|
||||||
|
"jest": true
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -516,6 +516,10 @@ LeetCode 与 LintCode 解题记录。此为个人练习仓库,代码中对重
|
|||||||
- LeetCode 108. 将有序数组转换为二叉搜索树 <https://leetcode-cn.com/problems/convert-sorted-array-to-binary-search-tree/>
|
- 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>
|
- 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)
|
- [合并 K 个排序链表](src/list/merge-k-sorted-lists.js)
|
||||||
|
@ -1,10 +1,4 @@
|
|||||||
/**
|
import TreeNode from '../../test/tree/TreeNode'
|
||||||
* Definition for a binary tree node.
|
|
||||||
*/
|
|
||||||
function TreeNode(val) {
|
|
||||||
this.val = val
|
|
||||||
this.left = this.right = null
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {number[]} nums
|
* @param {number[]} nums
|
||||||
|
12
src/tree/unique-binary-search-trees.js
Normal file
12
src/tree/unique-binary-search-trees.js
Normal 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
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
import { sortedArrayToBST } from '../../src/tree/convert-sorted-array-to-binary-search-tree.js'
|
import { sortedArrayToBST } from '../../src/tree/convert-sorted-array-to-binary-search-tree.js'
|
||||||
|
|
||||||
test('将有序数组转换为二叉搜索树', () => {
|
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 })
|
||||||
})
|
})
|
||||||
|
5
test/tree/unique-binary-search-trees.test.js
Normal file
5
test/tree/unique-binary-search-trees.test.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
import { numTrees } from '../../src/tree/unique-binary-search-trees'
|
||||||
|
|
||||||
|
test('不同的二叉搜索树', () => {
|
||||||
|
expect(numTrees(3)).toBe(5)
|
||||||
|
})
|
Reference in New Issue
Block a user