Skip to content

Commit 8db25f0

Browse files
committed
翻转二叉树
1 parent 00617e5 commit 8db25f0

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

invert_binary_tree.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# -*- coding: utf-8 -*-
2+
3+
class Solution:
4+
# @param root: a TreeNode, the root of the binary tree
5+
# @return: nothing
6+
def invertBinaryTree(self, root):
7+
# write your code here
8+
if root is None:
9+
return
10+
root.left, root.right = root.right, root.left
11+
self.invertBinaryTree(root.left)
12+
self.invertBinaryTree(root.right)

0 commit comments

Comments
 (0)