Iterative Python BFS Solution


  • 0

    alt text

    class Solution(object):
        def isSymmetric(self, root):
            if not root:
                return True
            queue = [root]
            while queue:
                value = [x.val if x else None for x in queue]
                if value[::-1] != value:
                    return False
                new_queue = []
                for node in queue:
                    if node:
                        new_queue.append(node.left)
                        new_queue.append(node.right)
                queue = new_queue
            return True

Log in to reply
 

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