struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
class Solution {
public:
TreeNode*head = NULL;
void dfs(TreeNode* root,TreeNode* &res){
if(!root)return;
dfs(root->left,res);
TreeNode* r = root->right;
if(!res)
res = root,head = res;
else{
res->right = root;root->left = res; res = root;
}
dfs(r,res);
}
TreeNode* Convert(TreeNode* pRootOfTree) {
if(!pRootOfTree) return pRootOfTree;
TreeNode*res = NULL;
dfs(pRootOfTree,res);
return this->head;
}
};