mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-06 23:28:29 +08:00
添加leetcode 226翻转二叉树python后序递归代码
This commit is contained in:
@ -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:
|
||||
|
Reference in New Issue
Block a user