Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[pull] master from youngyangyang04:master #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
pull merged 20 commits into AlgorithmAndLeetCode:master from youngyangyang04:master
Jul 24, 2023
Merged
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a9039c0
更新 404.左叶子之和 排版格式修复
jinbudaily Jul 21, 2023
f3a3701
更新 513.找树左下角的值 排版格式修复
jinbudaily Jul 21, 2023
bf6c4e7
更新 0112.路径总和 排版格式修复
jinbudaily Jul 21, 2023
fe93239
更新 0106.从中序与后序遍历序列构造二叉树 排版格式修复
jinbudaily Jul 21, 2023
b4eefe9
更新 0654.最大二叉树 排版格式修复
jinbudaily Jul 21, 2023
eadc704
更新 0617.合并二叉树 排版格式修复
jinbudaily Jul 21, 2023
ac239bc
更新 0700.二叉搜索树中的搜索 排版格式修复
jinbudaily Jul 21, 2023
7746734
更新 0098.验证二叉搜索树 排版格式修复
jinbudaily Jul 21, 2023
74bbca2
更新 0530.二叉搜索树的最小绝对差 排版格式修复
jinbudaily Jul 21, 2023
55b85b5
更新 0501.二叉搜索树中的众数 排版格式修复
jinbudaily Jul 23, 2023
3a2490b
更新 0236.二叉树的最近公共祖先 排版格式修复
jinbudaily Jul 23, 2023
07e1ccc
更新 0235.二叉搜索树的最近公共祖先 排版格式修复
jinbudaily Jul 23, 2023
7027116
更新 0701.二叉搜索树中的插入操作 排版格式修复
jinbudaily Jul 23, 2023
0f22ada
更新 0450.删除二叉搜索树中的节点 排版格式修复
jinbudaily Jul 23, 2023
e14e216
更新 0669.修剪二叉搜索树 排版格式修复
jinbudaily Jul 23, 2023
572c089
更新 0108.将有序数组转换为二叉搜索树 排版格式修复
jinbudaily Jul 23, 2023
6bf34cd
更新 0538.将二叉搜索树转换为累加树 排版格式修复
jinbudaily Jul 23, 2023
7539060
更新 二叉树总结篇 排版格式修复
jinbudaily Jul 23, 2023
2b6e851
Merge branch 'master' of github.com:jinbudaily/leetcode-master
jinbudaily Jul 23, 2023
dd04907
Merge pull request #2199 from jinbudaily/master
youngyangyang04 Jul 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
更新 0701.二叉搜索树中的插入操作 排版格式修复
  • Loading branch information
jinbudaily committed Jul 23, 2023
commit 70271161fff40fb3ab1929dcb37b19e3efe469b0
29 changes: 15 additions & 14 deletions problems/0701.二叉搜索树中的插入操作.md
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
* -10^8 <= val <= 10^8
* 新值和原始二叉搜索树中的任意节点值都不同

# 算法公开课
## 算法公开课

**《代码随想录》算法视频公开课:[原来这么简单? | LeetCode:701.二叉搜索树中的插入操作](https://www.bilibili.com/video/BV1Et4y1c78Y?share_source=copy_web),相信结合视频在看本篇题解,更有助于大家对本题的理解**。
**[《代码随想录》算法视频公开课](https://programmercarl.com/other/gongkaike.html):[原来这么简单? | LeetCode:701.二叉搜索树中的插入操作](https://www.bilibili.com/video/BV1Et4y1c78Y?share_source=copy_web),相信结合视频在看本篇题解,更有助于大家对本题的理解**。

# 思路
## 思路

这道题目其实是一道简单题目,**但是题目中的提示:有多种有效的插入方式,还可以重构二叉搜索树,一下子吓退了不少人**,瞬间感觉题目复杂了很多。

Expand All @@ -43,7 +43,7 @@

接下来就是遍历二叉搜索树的过程了。

## 递归
### 递归

递归三部曲:

Expand Down Expand Up @@ -165,7 +165,7 @@ public:
**网上千篇一律的代码,可能会误导大家认为通过递归函数返回节点 这样的写法是天经地义,其实这里是有优化的!**


## 迭代
### 迭代

再来看看迭代法,对二叉搜索树迭代写法不熟悉,可以看这篇:[二叉树:二叉搜索树登场!](https://programmercarl.com/0700.二叉搜索树中的搜索.html)

Expand Down Expand Up @@ -198,7 +198,7 @@ public:
};
```

# 总结
## 总结

首先在二叉搜索树中的插入操作,大家不用恐惧其重构搜索树,其实根本不用重构。

Expand All @@ -207,9 +207,9 @@ public:
最后依然给出了迭代的方法,迭代的方法就需要记录当前遍历节点的父节点了,这个和没有返回值的递归函数实现的代码逻辑是一样的。


# 其他语言版本
## 其他语言版本

## Java
### Java

```java
class Solution {
Expand Down Expand Up @@ -254,7 +254,7 @@ class Solution {
}
```
-----
## Python
### Python

递归法(版本一)
```python
Expand Down Expand Up @@ -371,7 +371,7 @@ class Solution:

```
-----
## Go
### Go

递归法

Expand Down Expand Up @@ -417,7 +417,7 @@ func insertIntoBST(root *TreeNode, val int) *TreeNode {
}
```
-----
## JavaScript
### JavaScript

有返回值的递归写法

Expand Down Expand Up @@ -530,7 +530,7 @@ var insertIntoBST = function (root, val) {
};
```

## TypeScript
### TypeScript

> 递归-有返回值

Expand Down Expand Up @@ -595,7 +595,7 @@ function insertIntoBST(root: TreeNode | null, val: number): TreeNode | null {
```


## Scala
### Scala

递归:

Expand Down Expand Up @@ -632,7 +632,7 @@ object Solution {
}
```

### rust
### Rust

迭代:

Expand Down Expand Up @@ -697,3 +697,4 @@ impl Solution {
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
<img src="../pics/网站星球宣传海报.jpg" width="1000"/>
</a>

AltStyle によって変換されたページ (->オリジナル) /