/**
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 ;
        }
        TreeNode l = pRootOfTree.left ;
        TreeNode r = pRootOfTree.right ;
        pRootOfTree.left = null ;
        pRootOfTree.right = null ;
        TreeNode Lh = Convert(l) ;
        TreeNode Rh = Convert(r) ;
        TreeNode cur = Lh ;
        while(cur != null && cur.right != null) {
            cur = cur.right ;
        }
        pRootOfTree.left = cur ;
        if(cur != null) {
            cur.right = pRootOfTree ;
        }
        pRootOfTree.right = Rh ;
        if(Rh != null) {
            Rh.left = pRootOfTree ;
        }
        return Lh == null ? pRootOfTree :  Lh;
    }
}