From ca89ca30975554cd3130eb6a2f6101c80723f99f Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Mon, 27 Nov 2023 10:16:15 +0800 Subject: [PATCH 1/3] =?UTF-8?q?Update=200700.=E4=BA=8C=E5=8F=89=E6=90=9C?= =?UTF-8?q?=E7=B4=A2=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 --- ...55\347\232\204\346\220\234\347\264\242.md" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git "a/problems/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.md" "b/problems/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.md" index bc21bab872..65e6921915 100644 --- "a/problems/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.md" +++ "b/problems/0700.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\255\347\232\204\346\220\234\347\264\242.md" @@ -464,6 +464,28 @@ impl Solution { } } ``` +### C# +```C# +// 递归 +public TreeNode SearchBST(TreeNode root, int val) +{ + if (root == null || root.val == val) return root; + if (root.val > val) return SearchBST(root.left, val); + if (root.val < val) return SearchBST(root.right, val); + return null; +} +// 迭代 +public TreeNode SearchBST(TreeNode root, int val) +{ + while (root != null) + { + if (root.val > val) root = root.left; + else if (root.val < val) root = root.right; + else return root; + } + return null; +} +```

From 7aef42def84ef94f198eedd85a946130319264da Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Tue, 28 Nov 2023 10:17:25 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Update=200098.=E9=AA=8C=E8=AF=81=E4=BA=8C?= =?UTF-8?q?=E5=8F=89=E6=90=9C=E7=B4=A2=E6=A0=91=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?C#=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...217\211\346\220\234\347\264\242\346\240\221.md" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git "a/problems/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" "b/problems/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" index 184060a5cd..319ad1aaa1 100644 --- "a/problems/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" +++ "b/problems/0098.\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.md" @@ -791,6 +791,20 @@ impl Solution { } } ``` +### C# +```C# +// 递归 +public long val = Int64.MinValue; +public bool IsValidBST(TreeNode root) +{ + if (root == null) return true; + bool left = IsValidBST(root.left); + if (root.val > val) val = root.val; + else return false; + bool right = IsValidBST(root.right); + return left && right; +} +```

From bc7f72cad70d1459f290a85f02447c43939606d3 Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Wed, 29 Nov 2023 09:05:34 +0800 Subject: [PATCH 3/3] =?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 --- ...17\347\273\235\345\257\271\345\267\256.md" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git "a/problems/0530.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\345\260\217\347\273\235\345\257\271\345\267\256.md" "b/problems/0530.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\345\260\217\347\273\235\345\257\271\345\267\256.md" index 56911858dd..f08df577d9 100644 --- "a/problems/0530.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\345\260\217\347\273\235\345\257\271\345\267\256.md" +++ "b/problems/0530.\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\234\200\345\260\217\347\273\235\345\257\271\345\267\256.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); + } +} +```