Symmetric Tree

Given the root of a binary tree, return true if the tree is a mirror of itself around its center. Pattern focus: Trust Recursion. Compare the left subtree and right subtree as mirror images.

Input Format

root = binary tree root

Output Format

true if the tree is symmetric, otherwise false

Constraints

  • 1 <= number of nodes <= 10^5
  • -10^4 <= node values <= 10^4
  • Input must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

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

Output:

true

Explanation:

The left and right subtrees are mirror images.

Example 2:

Input:

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

Output:

false

Explanation:

The subtree shapes are not mirrored.

Loading...
Symmetric Tree - Binary Tree DSA Problem