public class TreeNode {
    int val = 0;
    TreeNode left = null;
    TreeNode right = null;

    public TreeNode(int val) {
        this.val = val;

    }

}
*/
public class Solution {
    private TreeNode head=null;
    private TreeNode pLast=null;
    public TreeNode Convert(TreeNode pRootOfTree) {
        if(pRootOfTree==null) return null;
        
        //如果左子树为空,那么根结点为头结点
        Convert(pRootOfTree.left);
        if(head==null) head=pRootOfTree;
        
        pRootOfTree.left=pLast;
        if(pLast!=null) pLast.right=pRootOfTree;
        pLast=pRootOfTree;
        
        Convert(pRootOfTree.right);
        return head;
    }
}