Skip to content

Commit 68a239a

Browse files
committed
添加题701
1 parent 4e20e2e commit 68a239a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@
77
## 在线阅读
88

99
本算法模板主要参考自[greyireland](https://github.com/greyireland)[algorithm-pattern](https://github.com/greyireland/algorithm-pattern)项目,将其Go语言代码翻译成JavaScript语言代码。
10+
11+
## 核心内容
12+
13+
#### 数据结构篇 🐢
14+
15+
- [二叉树](https://github.com/ligecarryme/algorithm-pattern-JavaScript/blob/master/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E7%AF%87/%E4%BA%8C%E5%8F%89%E6%A0%91.md)

数据结构篇/二叉树.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,3 +457,21 @@ const helper = (node, smaller, bigger) => {
457457
}
458458
```
459459

460+
[701. 二叉搜索树中的插入操作](https://leetcode-cn.com/problems/insert-into-a-binary-search-tree/)
461+
462+
给定二叉搜索树(BST)的根节点和要插入树中的值,将值插入二叉搜索树。 返回插入后二叉搜索树的根节点。 输入数据 保证 ,新值和原始二叉搜索树中的任意节点值都不同。
463+
464+
```js
465+
var insertIntoBST = function (root, val) {
466+
if (root === null) {
467+
return new TreeNode(val)
468+
}
469+
if (root.val > val) {
470+
root.left = insertIntoBST(root.left, val)
471+
} else {
472+
root.right = insertIntoBST(root.right, val)
473+
}
474+
return root
475+
};
476+
```
477+

0 commit comments

Comments
 (0)