mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-14 06:55:41 +08:00
Update 0701.二叉搜索树中的插入操作.md
This commit is contained in:
@ -326,7 +326,22 @@ class Solution:
|
|||||||
return root
|
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
|
```python
|
||||||
|
Reference in New Issue
Block a user