/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
/*
在中序排列中插入一个node
node和pre之间建立联系
最后return的时候需要隔断某些联系
*/
class Solution {
public:
TreeNode * head;
void Inorder(TreeNode* pRootOfTree) {
if (!pRootOfTree) {
return;
}
Inorder(pRootOfTree->left);
TreeNode *node = new TreeNode(pRootOfTree->val);
head->right = node;
node->left = head;
head = head->right;
Inorder(pRootOfTree->right);
}
TreeNode* Convert(TreeNode* pRootOfTree) {
if (!pRootOfTree) {
return pRootOfTree;
}
head = new TreeNode(0);
TreeNode *ret = head;
Inorder(pRootOfTree);
ret->right->left = nullptr;
ret = ret->right;
return ret;
}
};