码迷,mamicode.com
首页 > 其他好文 > 详细

156. Binary Tree Upside Down

时间:2016-06-22 08:07:37      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

~~

 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     }

 

156. Binary Tree Upside Down

标签:

原文地址:http://www.cnblogs.com/warmland/p/5605711.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!