面试题27:二叉树的镜像(Python)

版权声明: https://blog.csdn.net/Hu_WF/article/details/88736670

牛客网题目链接

# -*- 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 here
        if root==None : return None
        self.Mirror(root.left)
        self.Mirror(root.right)
        root.left,root.right =root.right,root.left

猜你喜欢

转载自blog.csdn.net/Hu_WF/article/details/88736670