From bc7f72cad70d1459f290a85f02447c43939606d3 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Wed, 29 Nov 2023 09:05:34 +0800 Subject: [PATCH] =?UTF-8?q?Update=20530.=E4=BA=8C=E5=8F=89=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=E6=A0=91=E7=9A=84=E6=9C=80=E5=B0=8F=E7=BB=9D=E5=AF=B9?= =?UTF-8?q?=E5=B7=AE=EF=BC=8C=E6=B7=BB=E5=8A=A0C#=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0530.二叉搜索树的最小绝对差.md | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/problems/0530.二叉搜索树的最小绝对差.md b/problems/0530.二叉搜索树的最小绝对差.md index 56911858..f08df577 100644 --- a/problems/0530.二叉搜索树的最小绝对差.md +++ b/problems/0530.二叉搜索树的最小绝对差.md @@ -647,6 +647,27 @@ impl Solution { } } ``` +### C# +```C# +// 递归 +public class Solution +{ + public List res = new List(); + public int GetMinimumDifference(TreeNode root) + { + Traversal(root); + return res.SelectMany((x, i) => res.Skip(i + 1).Select(y => Math.Abs(x - y))).Min(); + + } + public void Traversal(TreeNode root) + { + if (root == null) return; + Traversal(root.left); + res.Add(root.val); + Traversal(root.right); + } +} +```