Python iterative BFS

  • 0
    class Solution(object):
        def invertTree(self, root):
            :type root: TreeNode
            :rtype: TreeNode
            level = [root] if root else []
            while level:
                q = []
                for node in level:
                    if node.left:
                    if node.right:
                    node.left, node.right = node.right, node.left
                level = q
            return root


Log in to reply

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