Pre-Order and Post-Order Traversals in the same Problem II
An interesting problem (which I guarantee you'll never see in real life) to turn a tree upside down (yeah, guaranteed). Three steps taken here: 1. A pre-order approach to find the new root (just a loop going thru the left nodes) 2. A post-order approach to turn every node upside down using the given rules 3. Make the original root a leaf node Code is down below, cheers, ACC. Binary Tree Upside Down - LeetCode 156. Binary Tree Upside Down Medium 258 346 Add to List Share Given the root of a binary tree, turn the tree upside down and return the new root . You can turn a binary tree upside down with the following steps: The original left child becomes the new root. The original root becomes the new right child. The original right child becomes the new left child. The mentioned steps are done level by level. It is guaranteed that every right node has a sibling (a left node with the same parent) and has no children. Example 1: Input: root = [1,2,3,4,5] Output: [4,5,2,null,null,