my simple BFS solution


  • 0
    M

    class Solution(object):

    def invertTree(self, root):
        """
        :type root: TreeNode
        :rtype: TreeNode
        """
        queue=[root]
        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.