Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 79623eb

Browse files
添加 0538.把二叉搜索树转换为累加树.md C语言
1 parent c5a9ead commit 79623eb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

problems/0538.把二叉搜索树转换为累加树.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,27 @@ var convertBST = function (root) {
293293
};
294294
```
295295

296+
##C
297+
298+
递归
299+
```c
300+
int pre;
301+
void traversal(struct TreeNode* node) {
302+
if(!node)
303+
return ;
304+
traversal(node->right);
305+
node->val = node->val + pre;
306+
pre = node->val;
307+
traversal(node->left);
308+
}
309+
310+
struct TreeNode* convertBST(struct TreeNode* root){
311+
pre = 0;
312+
traversal(root);
313+
return root;
314+
}
315+
```
316+
296317
-----------------------
297318
* 作者微信:[程序员Carl](https://mp.weixin.qq.com/s/b66DFkOp8OOxdZC_xLZxfw)
298319
* B站视频:[代码随想录](https://space.bilibili.com/525438321)

0 commit comments

Comments
 (0)