题目描述:
思路:利用递归实现左右节点的交换
# -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
# 返回镜像树的根节点
def Mirror(self, root):
# write code here
if root != None:
f = root.left
root.left = root.right
root.right = f
self.Mirror(root.left)
self.Mirror(root.right)
return root