剑指offer_二叉树_二叉树的镜像

二叉树的镜像

在这里插入图片描述
参考答案1
参考答案2

# -*- coding:utf-8 -*-
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None
class Solution:
    # 返回镜像树的根节点
    # 方式1:生成新的镜像二叉树
    def Mirror(self, root):
        if root == None:
            return
        root.left, root.right = root.right, root.left
        self.Mirror(root.left)
        self.Mirror(root.right)
        return root
发布了31 篇原创文章 · 获赞 0 · 访问量 725

猜你喜欢

转载自blog.csdn.net/freedomUSTB/article/details/105082015
今日推荐