剑指offer_第18题_二叉树的镜像_Python

题目描述

  • 将给定的二叉树,变换为其镜像

解题思路

思路1
递归

class Solution:
    # 返回镜像树的根节点
    def Mirror(self, root):
        if root:
            root.left,root.right=root.right,root.left
            if root.left:
                self.Mirror(root.left)
            if root.right:
                self.Mirror(root.right)
        else:
            return None

猜你喜欢

转载自blog.csdn.net/Datawhale/article/details/82630506
今日推荐