Update 0701.二叉搜索树中的插入操作.md
This commit is contained in:
parent
8c3d8aab25
commit
92c6be6e0a
|
|
@ -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
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue