add: 将有序数组转换为二叉搜索树

This commit is contained in:
yi-ge 2020-07-06 08:05:15 +08:00
parent 146b33a651
commit 41aa639602
2 changed files with 2 additions and 9 deletions

View File

@ -1,11 +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
* @return {TreeNode} * @return {TreeNode}

View File

@ -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 })
}) })