国内老牌的室内设计网站,产品推广渠道,广州网站营销推广设计,淮南教育网官网题目描述 操作给定的二叉树#xff0c;将其变换为源二叉树的镜像。输入描述: 二叉树的镜像定义#xff1a;源二叉树 8/ \6 10/ \ / \5 7 9 11镜像二叉树8/ \10 6/ \ / \11 9 7 5 # -*- coding:utf-8 -*-
# class TreeNode:
# def __init__(self, x):
# …题目描述 操作给定的二叉树将其变换为源二叉树的镜像。 输入描述: 二叉树的镜像定义源二叉树 8/ \6 10/ \ / \5 7 9 11镜像二叉树8/ \10 6/ \ / \11 9 7 5 # -*- 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 hereif not root:returnif root.left is None and root.right None:returnroot.left,root.right root.right,root.leftself.Mirror(root.left)self.Mirror(root.right)转载于:https://www.cnblogs.com/tianqizhi/p/9683618.html