Share my Non-recursive Python Solution

  • 1
    class Solution(object):
        def isSymmetric(self, root):
            stack = [root]
            while stack:
                value = [x.val if x else None for x in stack]
                if value[::-1] != value:
                    return False
                stack_new = []
                for x in stack:
                    if x:
                        stack_new += [x.left,x.right]
                stack = stack_new
            return True

Log in to reply

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