Clean python iterative solution

  • 0
    class Solution(object):
        def isSymmetric(self, root):
            if not root:
                return True
            stack, left, right = [], root.left, root.right
            while stack or left and right:
                if not (left or right):
                    right = stack.pop().left
                    left = stack.pop().right
                elif not left or not right or left.val != right.val:
                    return False
                    left, right = left.left, right.right
            return not (stack or left or right)

Log in to reply

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