题目链接:https://leetcode-cn.com/problems/dui-cheng-de-er-cha-shu-lcof/
难度:简单
描述:
请实现一个函数,用来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。
题解
# Definition for a binary tree node.# class TreeNode:# def __init__(self, x):# self.val = x# self.left = None# self.right = Noneclass Solution:def isSymmetric(self, root: TreeNode) -> bool:def recursion(l, r):if l is None and r is None:return Trueif l is None or r is None or l.val != r.val:return Falsereturn recursion(l.left, r.right) and recursion(l.right, r.left)if root is None:return Truereturn recursion(root.left, root.right)
