点击题目链接
思路
转换为子问题:左右子树相反转。遍历手法:后序遍历
代码
class Solution:def Transverse(self,root: TreeNode):if root == None:return rootnewleft = self.Transverse(root.left)newright = self.Transverse(root.right)# 对root节点处理root.left = newrightroot.right = newleftreturn rootdef Mirror(self , pRoot: TreeNode) -> TreeNode:# write code here# 子问题:左右子树相反转。遍历手法:后序遍历return self.Transverse(pRoot)