7 lines Python code

  • 2
    def isSymmetric(self, root):
        def check(r1, r2):
            if (r1 is None) != (r2 is None): return False
            if r1 is None: return True
            if r1.val != r2.val: return False
            return check(r1.left, r2.right) and check(r1.right, r2.left)
        if root is None: return True
        return check(root.left, root.right)

Log in to reply

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