AlgoLounge

Symmetric Tree

easy

LeetCode 101. Symmetric Tree

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

Examples

Example 1

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

1 / \ 2 2 / \ / \ 3 4 4 3Output: true

Example 2

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

1 / \ 2 2 \ \ 3 3Output: false

Constraints

  • The number of nodes in the tree is in the range [1, 1000]
  • -100 <= Node.val <= 100

How the tests work: trees are written as level-order arrays — [1,null,2] is a root 1 with a right child 2. Your function receives real TreeNode objects.

TypeScript
Loading editor…
List of test cases (8)
Case 1
root = [1,2,2,3,4,4,3]
Case 2
root = [1,2,2,null,3,null,3]
Case 3
root = [1]
Case 4
root = [1,2,2,2,null,2]
Case 5
root = [1,2,2,null,null,null,null]
Case 6
root = [5,4,4,3,null,null,3]
Case 7
root = [1,0,0,null,-1,-1,null]
Case 8
root = [2,3,3,4,5,5,4]