Reverse A Binary Tree (Left to Right) [closed]
You can use recursion. We swap the left and right child of a node, in-place, and then do the same for its children: static void reverseTree(final TreeNode root) { final TreeNode temp = root.right; root.right = root.left; root.left = temp; if (root.left != null) { reverseTree(root.left); } if (root.right != null) { reverseTree(root.right); } } … Read more