Leetcode-5050 Binary Search Tree to Greater Sum Tree(从二叉搜索树到更大和树)

第二题我完全没看懂他想表达什么,不过通过例子去理解,基本上就是右中左这种顺序把结点的值换一下吧

 1 class Solution
 2 {
 3     public:
 4         int rnt = 0;
 5         TreeNode* bstToGst(TreeNode* root)
 6         {
 7             if(!root)
 8                 return NULL;
 9             bstToGst(root->right);
10             int tmp = root->val;
11             root->val += rnt;
12             rnt += tmp;
13             bstToGst(root->left);
14             return root;
15         }
16 };
原文地址:https://www.cnblogs.com/Asurudo/p/10812278.html