题目描述:
操作给定的二叉树,将其变换为源二叉树的镜像。
输入描述:
思路:
Python实现1:
// An highlighted block
class Solution:
# 返回镜像树的根节点
def Mirror(self, root):
# write code here
if root != None:
root.left,root.right = root.right, root.left
self.Mirror(root.left)
self.Mirror(root.right)
python实现2:
// An highlighted block
class Solution:
# 返回镜像树的根节点
def Mirror(self, root):
# write code here
if not root:
return root
if not root.right and not root.left:
return root
if root.right or root.left:
t=root.right
root.right=root.left
root.left=t
self.Mirror(root.right)
self.Mirror(root.left)
return root