题解 | #二叉搜索树与双向链表#
二叉搜索树与双向链表
https://www.nowcoder.com/practice/947f6eb80d944a84850b0538bf0ec3a5
/** * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */ /** * * @param pRootOfTree TreeNode类 * @return TreeNode类 */ static struct TreeNode* p1 = NULL; static struct TreeNode* p2 = NULL; void makline(struct TreeNode* pRootOfTree ){ if(!pRootOfTree) return; makline(pRootOfTree->left ); if(p1 == NULL){ p1 = p2 = pRootOfTree; } else{ p2 = pRootOfTree; p1->right = p2; p2->left = p1; p1 = p1->right; } makline(pRootOfTree->right); } struct TreeNode* Convert(struct TreeNode* pRootOfTree ) { // write code here if(!pRootOfTree) return pRootOfTree; makline(pRootOfTree); while(pRootOfTree->left) pRootOfTree = pRootOfTree->left; return pRootOfTree; }