156. Binary Tree Upside Down

~~

 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     }

 

posted @ 2016-06-22 07:19  warmland  阅读(98)  评论(0编辑  收藏  举报