问题描述:
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 = right
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, left, right):
if not left and not right:
return True
if not left or not right or left.val != right.val:
return False
return self.isMirror(left.left, right.right) and self.isMirror(left.right, right.left)