Merge pull request #148 from QuinnDK/添加0701二叉搜索树中的插入操作

添加0701二叉搜索树中的插入操作Go版本
This commit is contained in:
Carl Sun 2021-05-16 21:22:28 +08:00 committed by GitHub
commit 77dc120234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 1 deletions

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