右根左遍历就行。
/**
* Definition for a binary tree node.
* struct TreeNode {
* int val;
* struct TreeNode *left;
* struct TreeNode *right;
* };
*/
void order(struct TreeNode* root,int * pre){
if(!root) return;
order(root->right,pre);
root->val=root->val+*pre;
*pre=root->val;
order(root->left,pre);
}
struct TreeNode* convertBST(struct TreeNode* root) {
int pre=0;
order(root,&pre);
return root;
}
结果;
标签:pre,TreeNode,struct,val,二叉,累加,root,order,538 From: https://www.cnblogs.com/llllmz/p/18059053