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

This commit is contained in:
jianghongcheng
2023-05-24 22:39:35 -05:00
committed by GitHub
parent 832897e4bb
commit 2f86a5ce27

View File

@ -326,7 +326,22 @@ class Solution:
return root
```
递归法(版本四)
```python
class Solution:
def insertIntoBST(self, root, val):
if root is None:
node = TreeNode(val)
return node
if root.val > val:
root.left = self.insertIntoBST(root.left, val)
if root.val < val:
root.right = self.insertIntoBST(root.right, val)
return root
```
迭代法
```python