101.Symmetric Tree

 

 

# Definition for a binary tree node.
# class TreeNode:
#     def __init__(self, x):
#         self.val = x
#         self.left = None
#         self.right = None

class Solution:
    def isSymmetric(self, root: TreeNode) -> bool:
        if root == None:
            return True
        else:
            return self.mirror(root.left, root.right)
    def mirror(self, p, q):
        if p == None and q == None:
            return True
        if p == None or q == None:
            return False
        if p.val == q.val:
            ans_l = self.mirror(p.left, q.right)
            ans_r = self.mirror(p.right, q.left)
            if ans_l == True and ans_r == True:
                return True
            else:
                return False
        else:
            return False

 

posted @ 2020-05-09 14:31  星海寻梦233  阅读(88)  评论(0编辑  收藏  举报