简单题101. 对称二叉树 (python)20240922
问题描述:
python:
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = rightclass Solution(object):def isSymmetric(self, root):""":type root: TreeNode:rtype: bool"""if not root:return Truereturn self.isMirror(root.left, root.right)def isMirror(self, left, right):if not left and not right:return Trueif not left or not right or left.val != right.val:return Falsereturn self.isMirror(left.left, right.right) and self.isMirror(left.right, right.left)