AcWing 39. 对称的二叉树
原题链接
简单
作者:
HaoGuo
,
2020-04-20 16:29:06
,
所有人可见
,
阅读 404
# Definition for a binary tree node.
# class TreeNode(object):
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution(object):
def isSymmetric(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
if not root: return True
return self.isMirror(root.left, root.right)
def isMirror(self, l, r):
if not l and not r: return True
if not l or not r or l.val!=r.val: return False
return self.isMirror(l.left, r.right) and self.isMirror(l.right, r.left)