int preSum = 0;
void traversal(TreeNode* root) {
if (!root) return;
traversal(root->right);
root->val += preSum;
preSum = root->val;
traversal(root->left);
}
TreeNode* convertBST(TreeNode* root) {
traversal(root);
return root;
}
虽然成绩不太好,但也不是不能看,关键是很简单地就过了
标签:TreeNode,val,traversal,力扣,return,preSum,二叉,root,538 From: https://www.cnblogs.com/yaocy/p/16994825.html