My simple BFS solution

  • 0

    class Solution(object):

    def isSymmetric(self, root):
        :type root: TreeNode
        :rtype: bool
        while queue and root:
            queue=[leaf for node in queue if node for leaf in (node.left,node.right)]
            stack=[node.val if node else 'null' for node in queue]
            if stack[::-1]!=stack: return False
        return True

Log in to reply

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