mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-07 15:45:40 +08:00
添加leetcode 226翻转二叉树python后序递归代码
This commit is contained in:
@ -322,6 +322,18 @@ class Solution:
|
|||||||
return root
|
return root
|
||||||
```
|
```
|
||||||
|
|
||||||
|
递归法:后序遍历:
|
||||||
|
```python
|
||||||
|
class Solution:
|
||||||
|
def invertTree(self, root: TreeNode) -> TreeNode:
|
||||||
|
if root is None:
|
||||||
|
return None
|
||||||
|
self.invertTree(root.left)
|
||||||
|
self.invertTree(root.right)
|
||||||
|
root.left, root.right = root.right, root.left
|
||||||
|
return root
|
||||||
|
```
|
||||||
|
|
||||||
迭代法:深度优先遍历(前序遍历):
|
迭代法:深度优先遍历(前序遍历):
|
||||||
```python
|
```python
|
||||||
class Solution:
|
class Solution:
|
||||||
|
Reference in New Issue
Block a user