Re: [闲聊] 每日leetcode

楼主: oin1104 (是oin的说)   2024-06-25 10:39:17
题目 :
把binary search tree
变成Greater Sum Tree
反正就是在二元搜寻树
对每个数字 把比他大的东西加起来
思路 :
好麻烦喔
重点就是你怎么遍历这棵树
反正就是先往右找到底
然后按照顺序找 先右再左
这样一定会是从大到小
然后把数字丢进全域变量
再弄回去
就写完了
可以打手枪了
好想打手枪
```cpp
class Solution {
public:
int all ;
void go(TreeNode* root)
{
if(root==NULL)return;
go(root->right);
all += root->val;
root->val = all;
go(root->left);
return;
}
TreeNode* bstToGst(TreeNode* root)
{
all = 0;
go(root);
return root;
}
};
```
作者: CanIndulgeMe (CIM)   2024-06-25 10:41:00
技术大神
作者: deatheo (逆十字)   2024-06-25 10:43:00
大神
作者: JIWP (JIWP)   2024-06-25 10:48:00
这题easy吧
作者: smart0eddie (smart0eddie)   2024-06-25 10:49:00
大师
作者: DJYOMIYAHINA (通通打死)   2024-06-25 10:51:00
你卷死我了
作者: Furina (芙宁娜)   2024-06-25 11:05:00
我好崇拜你

Links booklink

Contact Us: admin [ a t ] ucptt.com