Update 0701.二叉搜索树中的插入操作.md

This commit is contained in:
QuinnDK
2021-05-16 19:55:03 +08:00
committed by GitHub
parent 8c3d8aab25
commit 92c6be6e0a

View File

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