标签:
/** public class TreeNode { int val = 0; TreeNode left = null; TreeNode right = null; public TreeNode(int val) { this.val = val; } } */ public class Solution { public TreeNode Convert(TreeNode pRootOfTree) { if(pRootOfTree==null){ return null; } if(pRootOfTree.left==null&&pRootOfTree.right==null){ return pRootOfTree; } TreeNode left=Convert(pRootOfTree.left); TreeNode p=left; if(p!=null){ while(p.right!=null){ p=p.right; } p.right=pRootOfTree; pRootOfTree.left=p; } TreeNode right=Convert(pRootOfTree.right); if(right!=null){ right.left=pRootOfTree; pRootOfTree.right=right; } return left==null?pRootOfTree:left; } }
标签:
原文地址:http://www.cnblogs.com/tobemaster/p/5904794.html