Command Palette
Search for a command to run...
Problem 16.4 · Binary TreesEasy
What it teaches: Compare a tree with its own mirror: outer children with outer, inner with inner.
Practise it on judges as “Symmetric Tree”.
The problem
Return true if a binary tree is a mirror image of itself around its centre.
Example 1
Input: root = [1, 2, 2, 3, 4, 4, 3]
Output: true
Example 2
Input: root = [1, 2, 2, null, 3, null, 3]
Output: false
Constraints
Pattern clues in the wording
- → Mirror comparison of two subtrees
These clues point to Tree DFS: Recurse into the left and right children and combine what they return (height, sums, paths).
Stuck? Take one hint at a time
Solution.java · starterclass Solution {
public boolean isSymmetric(TreeNode root) {
return false;
}
}
Write your solution locally or in your editor for now. The in-browser runner (Java first, then Python, C++ and more) will run these tests right here.
Test cases
| # | Input | Expected |
|---|
| 1 | root = [1,2,2,3,4,4,3] | true |
| 2 | root = [1,2,2,null,3,null,3] | false |
+ 1 hidden test the code runner will check