/**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 leftNode = Convert(pRootOfTree.left);// TreeNode p = leftNode; while(p!=null && p.right!=null ){ p = p.right; } if(leftNode!=null){ p.right = pRootOfTree; pRootOfTree.left = p; } TreeNode rightNode = Convert(pRootOfTree.right); if(rightNode!=null){ rightNode.left = pRootOfTree; pRootOfTree.right = rightNode; } leftNode=leftNode!=null?leftNode:pRootOfTree; return leftNode; } }