链接:
https://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5?tpId=13&&tqId=11179&rp=1&ru=/activity/oj&qru=/ta/coding-interviews/question-ranking
描述:
代码:
/*
struct TreeNode {
int val;
struct TreeNode *left;
struct TreeNode *right;
TreeNode(int x) :
val(x), left(NULL), right(NULL) {
}
};*/
class Solution {
public:
void InOrder(TreeNode* cur,TreeNode*& prev){
if(cur == nullptr) return;
InOrder(cur->left, prev);
cur->left = prev;
if(prev) prev->right=cur;
prev=cur;
InOrder(cur->right, prev);
}
TreeNode* Convert(TreeNode* pRootOfTree) {
if(pRootOfTree==NULL) return NULL;
TreeNode* prev= nullptr;
InOrder(pRootOfTree, prev);
TreeNode* head = pRootOfTree;
while(head->left){
head = head->left;
}
return head;
}
};