root of a binary tree. Check whether the tree looks the same as its reflection across a vertical line through the root.
In other words, the root's left subtree must be a mirror copy of its right subtree: mirrored positions hold nodes with equal values, and wherever one side has no node, the other side has none either.
Return True if the tree is symmetric and False otherwise.
Try solving it both recursively and iteratively.root=tree_node([7, 5, 5, None, 8, 8]) → True
The left 5 has only a right child 8 and the right 5 has only a left child 8. They match in the mirror.
root=tree_node([7, 5, 5, 8, None, 8]) → False
Both 8s are left children, so in the mirror one of them lands opposite an empty spot.
root=tree_node([4]) → True
A single node is symmetric.
Node.val ≤ 100root=tree_node([7, 5, 5, None, 8, 8])
True
Run checks the first 3 tests in your browser. Submit checks all 114 tests on the server, hidden ones included.