15% off all plans & roadmaps Use code
See plansLeetCode 101 · Solution & editorial
Given the root of a binary tree, check whether it is a mirror of itself (i.e., symmetric around its center).
Symmetric Tree is a Tree Traversal Patterns (DFS & BFS) problem, in the Recursive Preorder Traversal subpattern. The pattern covers preorder, inorder, level order traversal, LCA, and serialization
Master preorder traversal for tree construction, inversion, and path problems. Visit root before children.
The reference solution runs in O(n) time and O(h) space.
Symmetric Tree has been reported in interviews at Capital One, Amazon, Yandex, Apple, Uber, Google, Microsoft.
The full editorial is part of Pro
It explains the core insight, the complexity analysis and the common mistakes, with a worked solution.
Symmetric Tree is a Tree Traversal Patterns (DFS & BFS) problem, in the Recursive Preorder Traversal subpattern. Once the approach above makes sense, write it yourself and then work through the neighbouring problems that reuse it.