添加 0538.把二叉搜索树转换为累加树.md C语言

This commit is contained in:
Arthur
2021-10-26 15:59:35 +01:00
parent c5a9eadab1
commit 79623eba4a

View File

@ -293,6 +293,27 @@ var convertBST = function (root) {
};
```
##C
递归
```c
int pre;
void traversal(struct TreeNode* node) {
if(!node)
return ;
traversal(node->right);
node->val = node->val + pre;
pre = node->val;
traversal(node->left);
}
struct TreeNode* convertBST(struct TreeNode* root){
pre = 0;
traversal(root);
return root;
}
```
-----------------------
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
* B站视频[代码随想录](https://space.bilibili.com/525438321)