对称二叉树
2019-12-21 本文已影响0人
而立之年的技术控
微信图片_20191221221729.jpg
class Solution:
def isSymmetric(self, root: TreeNode) -> bool:
def compare(left, right):
if left == None and right == None:
return True
if left == None:
return False
if right == None:
return False
if left.val != right.val:
return False
else:
res1 = compare(left.left, right.right)
res2 = compare(left.right, right.left)
return res1 and res2
if not root:
return True
else:
res = compare(root.left, root.right)
return res