1.Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST
2.英语不好的我一开始都看不懂啥意思...百度翻译啦啦啦
3./**
* Definition of TreeNode:
* class TreeNode {
* public:
* int val;
* TreeNode *left, *right;
* TreeNode(int val) {
* this->val = val;
* this->left = this->right = NULL;
* }
* }
*/
class Solution {
public:
/**
* @param root the root of binary tree
* @return the new root
*/
int s=0;
TreeNode* convertBST(TreeNode* root) {
// Write your code here
if(root==NULL)return NULL;
convertBST(root->right);
root->val=s+root->val;
s=root->val;
convertBST(root->left);
return root;
}
};
4.一开始完全看不懂题.看了看同学的也完全不懂,感觉特别难,只能看看同学的复制上了......
本文介绍了一种将二叉搜索树(BST)转换为大于树的方法,其中每个节点的值变为原值加上BST中所有大于该值的节点之和。通过递归遍历并调整节点值实现。

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



