View on GitHub

leetcode-diaries

A journal to record the solution of the various Leetcode problems solved over the course of time.

Invert Binary Tree

Leetcode problem 226 Difficulty: Easy

Problem Statement

Given the root of a binary tree, invert the tree, and return its root.

Constraints:

Example 1:

image

Input: root = [4,2,7,1,3,6,9]

Output: [4,7,2,9,6,3,1]

Example 2:

image

Input: root = [2,1,3]

Output: [2,3,1]

Example 3:

Input: root = []

Output: []

Submitted Solution

The implemented solution received the following rating on Leetcode:

image