~~
1 public TreeNode upsideDownBinaryTree(TreeNode root) { 2 if(root == null) { 3 return null; 4 } 5 return helper(root, null, null); 6 } 7 8 private TreeNode helper(TreeNode root, TreeNode parent, TreeNode sibling) { 9 TreeNode left = root.left; 10 TreeNode right = root.right; 11 root.left = sibling; 12 root.right = parent; 13 if(left == null) { 14 return root; 15 } 16 return helper(left, root, right); 17 }
原文:http://www.cnblogs.com/warmland/p/5605711.html