Facebook PixelInvert Binary Tree — Coding Practice
Invert Binary TreeEasy

Invert Binary Tree

Easy 14.1k76% acceptance
TreeDepth-First Search

Given the root of a binary tree, invert it (mirror left and right subtrees everywhere) and return the root.

Example 1
Input: root = [4,2,7,1,3,6,9]
Output: [4,7,2,9,6,3,1]
Constraints
  • 0 ≤ number of nodes ≤ 100
  • -100 ≤ Node.val ≤ 100
Asked atGoogleAmazon
JavaScript
Loading editor…
Case 1
[4,2,7,1,3,6,9]
expected: [4,7,2,9,6,3,1]
Case 2
[2,1,3]
expected: [2,3,1]
Case 3
[]
expected: []
Case 4
[1]
expected: [1]
Case 5
[1,2]
expected: [1,null,2]