To prove safety offer_ binary tree binary tree _ a mirror

Binary Tree Mirror

Here Insert Picture Description
Answers 1
Answers 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
Published 31 original articles · won praise 0 · Views 725

Guess you like

Origin blog.csdn.net/freedomUSTB/article/details/105082015