Symmetric Tree

IF
AlgoAxiomStaff Engineers
JSTS
Easy20 mins

Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).

Examples

Example 1:

1223443

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

Output: true

Explanation: The tree is symmetric. The left subtree [2, 3, 4] is a mirror of the right subtree [2, 4, 3].

Example 2:

12233

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

Output: false

Explanation: The tree is not symmetric. Both sides have a 3 on the right, but a mirror would require a 3 on the left of the right subtree.

Example 3:

1

Input: root = [1]

Output: true

Constraints

  • The number of nodes in the tree is in the range [1, 1000]
  • -100 <= Node.val <= 100
Source: Tree Depth-First Search pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle