添加leetcode 226翻转二叉树python后序递归代码

This commit is contained in:
Logen
2022-12-28 09:45:31 -06:00
parent c3d466ea85
commit b6807a66dc

View File

@ -322,6 +322,18 @@ class Solution:
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
class Solution: