Skip to content
Onsite

Symmetric Tree

EasyP2Coding

Given the root of a binary tree, return true if the tree is a mirror image of itself around its centre: the left subtree is the mirror of the right subtree, values included.

Example 1

Input
root = [1,2,2,3,4,4,3]
Output
true

Example 2

Input
root = [1,2,2,null,3,null,3]
Output
false
Why
Both 2s have a right child 3, so the shapes are not mirrored.

Constraints

  • 1 <= number of nodes <= 1000
  • -100 <= Node.val <= 100

Hints

Run checks the 3 visible tests, Submit all 9.