🟢 剑指 Offer 28. 对称的二叉树
LeetCode 提示
题目难度 简单
原题链接 🔗 leetcode
#
题解 1.py# 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 isSym(left, right): if left is None and right is None: return True if left is None or right is None: return False return left.val == right.val and isSym(left.left, right.right) and isSym(left.right, right.left) return isSym(root, root)