给定一个二叉树,检查它是否是镜像对称的。
方案一:
class Solution(object):
def isSymmetric(self, root):
"""
:type root: TreeNode
:rtype: bool
"""
def issametree(l, r):
if not l and not r:
return True
if l and r and l.val == r.val:
return issametree(l.left, r.right) and issametree(r.left, l.right)
else:
return False
if not root:
return True
return issametree(root.left, root.right)