/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { public: void link(TreeNode *root,TreeNode** last) { if(!root) return ; TreeNode* cur=root; if(cur->left) link(cur->left,last); cur->left=*last; if((*last)!=NULL) (*last)->right=cur; *last=cur; if(cur->right) link(cur->right,last); } TreeNode* Convert(TreeNode* pRootOfTree) { TreeNode * last=NULL; link(pRootOfTree,&last); while(last!=NULL&&last->left!=NULL) last=last->left; return last; } };