my simple BFS solution

  • 0

    class Solution(object):

    def invertTree(self, root):
        :type root: TreeNode
        :rtype: TreeNode
        while queue and root:
            for node in queue:
                node.left, node.right=node.right, node.left
            queue=[leaf for node in queue for leaf in (node.left,node.right) if leaf]
        return root

Log in to reply

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