对称二叉树
算法1
class Solution(object):
def isSymmetric(self, root):
“”“
:type root: TreeNode
:rtype: bool
“”“
if not root:
return True
return self.isSym(root.left,root.right)
def isSym(self,left,right):
if not left or not right:
return not left and not right
if left.val != right.val:
return False
return self.isSym(left.left,right.right) and self.isSym(left.right,right.left)