美文网首页
101 Symmetric Tree

101 Symmetric Tree

作者: Closears | 来源:发表于2015-06-16 16:34 被阅读20次

    原题链接: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

    相关文章

      网友评论

          本文标题:101 Symmetric Tree

          本文链接:https://www.haomeiwen.com/subject/rsksqttx.html