Your app supports right-to-left languages. To flip a split-pane layout, every pane's left and right children must swap places, all the way down the tree.
Write mirrorLayout(root) that mirrors the tree and returns its root. You may change the tree in place or build a new one.
Input: root = [1,2,3,4,5] Output: [1,3,2,null,null,5,4]
2 and 3 swap, then 2's children 4 and 5 swap.
Input: root = [8,null,9] Output: [8,9]
The only child moves from the right side to the left side.
0 <= number of panes <= 10000Trees 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 #317 Mirror the Layout. 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.