Invert Binary Tree - aloalgo

Invert Binary Tree

Easy

You are given the root of a binary tree.

Your task is to invert the binary tree.

Note that:

  • Inverting a binary tree means swapping the left and right children of every node.
  • This operation should be applied recursively to all nodes, effectively mirroring the tree structure.

Do not return anything, instead modify the input tree.

Example 1

Input
12
Output
12

Example 2

Input
4213769
Output
4796231

Example 3

Input
213
Output
231

Example 4

Input
None
Output
None
Explanation:

An empty tree remains empty after inversion.

Loading...

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!