From e59dbae465c5247ff044a7d7fecd0b1cb6e22efe Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Sun, 10 Dec 2023 09:25:18 +0800 Subject: [PATCH] =?UTF-8?q?update538.=E6=8A=8A=E4=BA=8C=E5=8F=89=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A0=91=E8=BD=AC=E6=8D=A2=E4=B8=BA=E7=B4=AF=E5=8A=A0?= =?UTF-8?q?=E6=A0=91=EF=BC=8C=E6=B7=BB=E5=8A=A0C#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0538.把二叉搜索树转换为累加树.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/problems/0538.把二叉搜索树转换为累加树.md b/problems/0538.把二叉搜索树转换为累加树.md index c403c98f..07cae1ad 100644 --- a/problems/0538.把二叉搜索树转换为累加树.md +++ b/problems/0538.把二叉搜索树转换为累加树.md @@ -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; + } +} +```