A design system checks that a dashboard layout looks the same when flipped left to right. The layout is a binary tree of widget sizes.
Write isSymmetric(root) that returns true if the tree is a mirror image of itself around its center, and false otherwise. An empty tree is symmetric.
Input: root = [7,4,4,1,9,9,1] Output: true
The left side 4 (1, 9) mirrors the right side 4 (9, 1).
Input: root = [7,4,4,null,1,null,1] Output: false
Both 1s are right children, so the sides don't mirror each other.
0 <= number of widgets <= 100001 <= size <= 100Trees are written level by level, like [1, 2, 3, null, 4], where null is a missing child. Your function works with TreeNode objects, each with val, left, and right.
Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #319 Mirror-Symmetric Dashboard. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.