

/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* TreeNode *left;
* TreeNode *right;
* TreeNode() : val(0), left(nullptr), right(nullptr) {}
* TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
* TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
* };
*/
class Solution {
public:
// 反向中序遍历
int sum = 0;
TreeNode* convertBST(TreeNode* root) {
if(root==NULL)
return NULL;
if(root->right)
convertBST(root->right);
sum = sum + root->val;
root->val = sum;
if(root->left)
convertBST(root->left);
return root;
}
};