题目:
代码(首刷看解析 2024年1月31日):
class Solution {
public:int pre = 0;TreeNode* convertBST(TreeNode* root) {if (!root) return nullptr;root->right = convertBST(root->right);if (pre == 0) {pre = root->val;}else {root->val += pre;pre = root->val;}root->left = convertBST(root->left);return root;}
};