【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)
        
        
        
       
上一篇:生产环境的redis高可用集群搭建


下一篇:github上所有项目的受欢迎程度排名,包括超大型项目