1 2 3 4 5 6 7 8 9 10 11 12 13 14
| public class BinaryTreeUpsideDown { public TreeNode UpsideDownBinaryTree(TreeNode root) { TreeNode node = root, parent = null, right = null; while (node != null) { TreeNode left = node.left; node.left = right; right = node.right; node.right = parent; parent = node; node = left; } return parent; } }
|