update538.把二叉搜索树转换为累加树,添加C#
This commit is contained in:
parent
0e55c1b424
commit
e59dbae465
|
|
@ -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">
|
<p align="center">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue