mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 00:43:04 +08:00
update538.把二叉搜索树转换为累加树,添加C#
This commit is contained in:
@ -529,6 +529,23 @@ impl Solution {
|
||||
}
|
||||
}
|
||||
```
|
||||
### C#
|
||||
```C#
|
||||
// 递归
|
||||
public class Solution
|
||||
{
|
||||
int pre = 0;
|
||||
public TreeNode ConvertBST(TreeNode root)
|
||||
{
|
||||
if (root == null) return null;
|
||||
ConvertBST(root.right);
|
||||
root.val += pre;
|
||||
pre = root.val;
|
||||
ConvertBST(root.left);
|
||||
return root;
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
<p align="center">
|
||||
|
Reference in New Issue
Block a user