mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 19:44:45 +08:00
Merge pull request #148 from QuinnDK/添加0701二叉搜索树中的插入操作
添加0701二叉搜索树中的插入操作Go版本
This commit is contained in:
@ -271,6 +271,20 @@ class Solution:
|
||||
|
||||
|
||||
Go:
|
||||
```Go
|
||||
func insertIntoBST(root *TreeNode, val int) *TreeNode {
|
||||
if root == nil {
|
||||
root = &TreeNode{Val: val}
|
||||
return root
|
||||
}
|
||||
if root.Val > val {
|
||||
root.Left = insertIntoBST(root.Left, val)
|
||||
} else {
|
||||
root.Right = insertIntoBST(root.Right, val)
|
||||
}
|
||||
return root
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
@ -279,4 +293,4 @@ Go:
|
||||
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
|
||||
* B站视频:[代码随想录](https://space.bilibili.com/525438321)
|
||||
* 知识星球:[代码随想录](https://mp.weixin.qq.com/s/QVF6upVMSbgvZy8lHZS3CQ)
|
||||
<div align="center"><img src=../pics/公众号.png width=450 alt=> </img></div>
|
||||
<div align="center"><img src=../pics/公众号.png width=450 alt=> </img></div>
|
||||
|
Reference in New Issue
Block a user