Invert Binary Tree

TREE
DEPTH-FIRST SEARCH
BREADTH-FIRST SEARCH
BINARY TREE

Problem

Given the root of a binary tree, invert the tree, and return its root. Inverting a binary tree means that each left child becomes a right child, and every right child becomes a left child.

Examples

invertTree([1,2,3]) // [1,3,2]

invertTree([1,2]) // [1,null,2]
invertTree([1,2,3,4,5,6,7]) // [1,3,2,7,6,5,4] invertTree([1]) // [1]
Loading...
1
2
3