algoblazerEarly Access
LearnProblemsLeaderboard
Log inSign up

All problems

‹ Back to map
1 shown · 0/261 solved

Mirror a Binary Tree

Bronze
Asked atSiemens
Solve problem →
2000ms256MBAdded Aug 22, 2026

Given the root of a binary tree, mirror it by swapping the left and right children of every node. Return the root of the mirrored tree.

Tree Encoding

Your function receives root as a TreeNode (or the empty tree, as null) and returns the root of the mirrored tree. The node type is provided for you, with val, left and right fields; you may mirror in place and return the same root.

The examples below write trees as their level-order traversal, where null marks a missing child of a listed node and trailing nulls are omitted. That is only how trees are displayed; the encoding and decoding are done for you.

Constraints

  • The number of nodes in the tree is in the range [0,100][0, 100][0,100].
  • −100≤-100 \leq−100≤ Node.val ≤100\leq 100≤100

Details

Solved by3 people
Time limit2000ms
Memory256MB
AddedAug 22, 20262 weeks ago