Practice/LinkedIn/Leetcode 101. Symmetric Tree
CodingMust
Given the root of a binary tree, determine whether it exhibits mirror symmetry around its vertical center axis. A tree is considered symmetric if you can draw a vertical line through the root and the left side is a perfect reflection of the right side.
For the tree to be symmetric, every node on the left subtree must have a corresponding node at the mirrored position in the right subtree with the same value. Additionally, the structural arrangement must also be mirrored.
true if the tree is symmetric, false otherwisetrue)true)[0, 1000]-100 <= Node.val <= 100Example 1:
`
Input: root = [1, 2, 2, 3, 4, 4, 3]
Tree structure:
1
/
2 2
/ \ /
3 4 4 3
Output: true Explanation: The left subtree (2, 3, 4) mirrors the right subtree (2, 4, 3). Each corresponding position has matching values. `
Example 2:
`
Input: root = [1, 2, 2, null, 3, null, 3]
Tree structure:
1
/
2 2
\
3 3
Output: false Explanation: The right children don't mirror each other. The left subtree's node 2 has a right child, while the right subtree's node 2 also has a right child (should be left child for symmetry). `
Example 3:
Input: root = [1] Output: true Explanation: A tree with only one node is symmetric.