LeetCode 226, Easy. Topics: Tree, Depth-First Search, Breadth-First Search, Binary Tree. View on LeetCode.
Generate this problem as a practice environment: tested reference solution, 15 parametrized pytest cases, and a playground notebook:
Problem
Given the root of a binary tree, invert the tree, and return its root.
Examples
Constraints
- The number of nodes in the tree is in the range [0, 100]
- -100 <= Node.val <= 100
Solution
Reference implementation from solution.py on GitHub, full suite in test_solution.py:
Complexity
Grind 75, Grind, Blind 75, NeetCode 150, NeetCode 250, NeetCode All. Last modified on September 7, 2026