← DiffPush

Symmetric Tree (Mirror of Itself)

Standard Bar Binary Trees · Medium Problems O(n) · O(h)

The Mirror-Wing Kite Test

A kite maker balances a two-wing kite and demands true mirror symmetry: the left wing's every fork must reflect the right wing's — left arms matching right arms, values identical at mirrored joints. Before the kite flies, one check certifies the whole frame as aerodynamically balanced or flags it for rebuild.

Input: The root of a binary tree given as a level-order array where null marks a missing child.

Output: Return true if the tree is a mirror image of itself around the root, false otherwise.

Constraints

Examples

Example 1

Input: {"tree":[1,2,2,3,4,4,3]}
Output: true
Both wings fork identically with mirrored values 3 and 4.

Example 2

Input: {"tree":[1,2,2,null,3,null,3]}
Output: false
Both 3s hang on the same side of their wings — not mirrored.

Solve this in your browser →

Also on LeetCode ↗