对称二叉树


# 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:
        def is_mirrow(a, b):
            if a is None and b is None: return True
            if a is None or b is None: return False
            if a.val != b.val: return False
            return is_mirrow(a.left, b.right) and is_mirrow(a.right, b.left)
        
        if not root: return True
        return is_mirrow(root.left, root.right)


原文地址:https://www.cnblogs.com/KbMan/p/14498223.html