Python 11 lines code

  • 0
    class Solution(object):
        def isSymmetric(self, root):
            if root==None:
                return True
            def isSubSymmetric(lnode,rnode):
                if lnode==None and rnode==None:
                    return True
                elif lnode==None or rnode==None or lnode.val!=rnode.val:
                    return False
                return isSubSymmetric(lnode.left,rnode.right) and isSubSymmetric(lnode.right,rnode.left)
            return isSubSymmetric(root.left,root.right)

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.