/* struct TreeNode { int val; struct TreeNode *left; struct TreeNode *right; TreeNode(int x) : val(x), left(NULL), right(NULL) { } };*/ class Solution { public: TreeNode* Convert(TreeNode* pRootOfTree) { if(pRootOfTree==nullptr){ return nullptr; } if(pRootOfTree->left!=nullptr){ TreeNode *pl=Convert(pRootOfTree->left); while(pl->right!=nullptr){ pl=pl->right; } pl->right=pRootOfTree; pRootOfTree->left=pl; } if(pRootOfTree->right!=nullptr){ TreeNode *pr=Convert(pRootOfTree->right); pr->left=pRootOfTree; pRootOfTree->right=pr; } TreeNode *p=pRootOfTree; while(p->left!=nullptr){ p=p->left; } return p; } };