diff --git a/problems/0226.翻转二叉树.md b/problems/0226.翻转二叉树.md index ad2a7de2..84c0c589 100644 --- a/problems/0226.翻转二叉树.md +++ b/problems/0226.翻转二叉树.md @@ -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: