LeetCode-101. 对称二叉树
给定一个二叉树,检查它是否是镜像对称的。
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def isSymmetric(self, root: TreeNode) -> bool:
if not root:
return True
def issy(a, b):
if not a and not b:
return True
elif a and b and a.val == b.val:
return issy(a.left, b.right) and issy(a.right, b.left)
else:
return False
return(issy(root.left, root.right))