101 Symmetric Tree
2015-06-16 本文已影响20人
Closears
原题链接:Symmetric Tree
class Solution:
# @param {TreeNode} root
# @return {boolean}
def isSymmetric(self, root):
if root is None:
return True
return self.isSy(root.left, root.right)
def isSy(self, root1, root2):
if root1 is None and root2 is None:
return True
elif root1 is None or root2 is None:
return False
else:
if root1.val == root2.val:
return self.isSy(root1.left, root2.right) and self.isSy(root1.right, root2.left)
return False