846. Check if Binary Tree is Symmetric

EasyTreesBinary TreeDFSRecursion

Given the root of a binary tree, determine whether it is symmetric (a mirror image of itself around its center). Return true or false. The tree is given as a level-order array with null for missing children.

Input: A level-order array of the tree.

Output: Boolean — true or false.

Examples

Example 1
Input: [1,2,2,3,4,4,3]
Output: true
Explanation: The tree mirrors itself.
Example 2
Input: [1,2,2,null,3,null,3]
Output: false
Explanation: Not a mirror image.
Example 3
Input: [1]
Output: true
Explanation: Single node is symmetric.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →