/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
struct TreeNode* _increasingBST(struct TreeNode* root, struct TreeNode* pre){
if(!root){
return pre;
}
struct TreeNode* p = _increasingBST(root->left, root);
root->left = NULL;
root->right = _increasingBST(root->right, pre);
return p;
}
struct TreeNode* increasingBST(struct TreeNode* root){
return _increasingBST(root, NULL);
}
给你一个树,请你 按中序遍历 重新排列树,使树中最左边的结点现在是树的根,并且每个结点没有左子结点,只有一个右子结点。
最新推荐文章于 2021-04-25 14:46:28 发布
此篇博客介绍了如何使用递归方法将给定的二叉树转换为一个递增的二叉搜索树(BST),通过`_increasingBST`函数实现,展示了从根节点开始调整左右子树的步骤。
2657

被折叠的 条评论
为什么被折叠?



