第四题

作者: 鳕鳕鳕鳕小鱼 | 来源:发表于2020-05-24 22:29 被阅读0次
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/5/22 下午5:03
# @Author : Yuxiaoxue# @Site : 
# @File : ques4.py
# @Software: PyCharm


'''
题目描述:

操作给定的二叉树,将其变换为源二叉树的镜像。

'''

#定义一个二叉树节点
class Node(object):
    def __init__(self, left, right):
        self.value = root
        self.left = None
        self.right = None


def Mirror(root):
    if root == None:
        return None
    root.left, root.right = root.right, root.left
    Mirror(root.left)
    Mirror(root.right)


'''
上传答案
#定义一个二叉树节点
class Node(object):
    def __init__(self, left, right):
        self.value = root
        self.left = None
        self.right = None

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


'''

相关文章

网友评论

      本文标题:第四题

      本文链接:https://www.haomeiwen.com/subject/thpsahtx.html