• 【leetcode❤python】101. Symmetric Tree


    #-*- coding: UTF-8 -*-
    # Definition for a binary tree node.
    # class TreeNode(object):
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None

    class Solution(object):
        resultBool=True
        def isSymmetric(self, root):
            """
            :type root: TreeNode
            :rtype: bool
            """
            if root==None:return True
            if root.left==root.right==None:return True
            elif root.left==None or root.right==None:return False
            if root.left.val==root.right.val:
                self.dnf(root.left,root.right)
                return self.resultBool
            else:
                return False
        
        
        def dnf(self,root1,root2):
            
            if root1==None and root2==None:return
            elif root1==None or root2==None :self.resultBool=False;return
            
            if root1.val!=root2.val:
                self.resultBool=False
               
            self.dnf(root1.left,root2.right)
            self.dnf(root1.right,root2.left)
            
            
            
           
  • 相关阅读:
    Nacos配置管理-什么是配置中心
    MYSQL count
    贷款
    短视频推荐图书
    前端
    err
    err
    Mysql8安装教程
    err
    err
  • 原文地址:https://www.cnblogs.com/kwangeline/p/5953465.html
Copyright © 2020-2023  润新知