我们思考递归的时候一定不要去一步一步看它执行了啥,只会更绕。
事实上这题不难,但是我不熟悉二叉树,题目见过了,下次就没什么问题了。
# 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 not root:
return None
root.left,root.right=root.right,root.left
self.Mirror(root.left)
self.Mirror(root.right)
return root