Update 0701.二叉搜索树中的插入操作.md
This commit is contained in:
parent
832897e4bb
commit
2f86a5ce27
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in New Issue