Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b6807a6

Browse files
添加leetcode 226翻转二叉树python后序递归代码
1 parent c3d466e commit b6807a6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

‎problems/0226.翻转二叉树.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,18 @@ class Solution:
322322
return root
323323
```
324324

325+
递归法:后序遍历:
326+
```python
327+
class Solution:
328+
def invertTree(self, root: TreeNode) -> TreeNode:
329+
if root is None:
330+
return None
331+
self.invertTree(root.left)
332+
self.invertTree(root.right)
333+
root.left, root.right = root.right, root.left
334+
return root
335+
```
336+
325337
迭代法:深度优先遍历(前序遍历):
326338
```python
327339
class Solution:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /