Skip to main content
Back to problems
Leetcode
Medium
Trees
Recursion
Queues
Symmetric Tree

Determine whether a binary tree is a mirror of itself around its center.

Acceptance 100%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Symmetric Tree

Given the root of a binary tree, determine whether the tree is symmetric around its center.

A binary tree is symmetric if the left subtree is a mirror reflection of the right subtree. In other words, the left and right halves should match in structure and node values when viewed as mirrors.

Return true if the tree is symmetric, otherwise return false.

Key idea

You need to compare nodes in mirrored positions, not just traverse the tree in one order.

Input Format

  • A binary tree root node is provided as the input.
  • Each node contains an integer value and pointers to left and right children.

Output Format

  • Return true if the tree is symmetric.
  • Otherwise return false.

Constraints

  • The number of nodes is at least 0.
  • Node values may repeat.
  • The tree can be empty.
Examples
Sample cases returned by the problem API.

Example 1

Input

root = [1,2,2,3,4,4,3]

Output

true

Explanation

The left and right subtrees are mirror images of each other.

Example 2

Input

root = [1,2,2,null,3,null,3]

Output

false

Explanation

The structure differs on the two sides, so the tree is not symmetric.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.