Invert Binary Tree

Binary Tree
Easy

Approach

Diagrams

Analysis

Time

Space

from collections import deque


class Solution:
     def invertTree(self, root):
        queue = deque([root])

        while queue:
            node = queue.popleft()

            if not node:
                continue

            node.left, node.right = node.right, node.left

            queue.append(node.left)
            queue.append(node.right)

        return root

Learn

#Breadth-First Search

Videos