Symmetric Tree
Given the root of a binary tree, return true if the tree is a mirror image of itself around its center, i.e. symmetric.
Open official problem prompt ↗Determine whether a binary tree looks the same when reflected left-to-right about its root.
Fold the tree down the middle like a paper butterfly: it is symmetric if the left wing lands exactly on the right wing, node for node.
- Input
- root = [1, 2, 2, 3, 4, 4, 3]
- Output
- true
- Why
- The left subtree (2,3,4) is the mirror of the right subtree (2,4,3), so the whole tree reflects onto itself.
The number of nodes is in the range [1, 1000]-100 <= Node.val <= 100