From 7692d6cc97a999016aa0bd023433a2e0975e262d Mon Sep 17 00:00:00 2001 From: eeee0717 Date: Fri, 8 Dec 2023 08:08:10 +0800 Subject: [PATCH] =?UTF-8?q?Update=200669.=E4=BF=AE=E5=89=AA=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#?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0669.修剪二叉搜索树.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/problems/0669.修剪二叉搜索树.md b/problems/0669.修剪二叉搜索树.md index 00186558..229a2ab1 100644 --- a/problems/0669.修剪二叉搜索树.md +++ b/problems/0669.修剪二叉搜索树.md @@ -567,6 +567,23 @@ impl Solution { } } ``` +### C# +```C# +// 递归 +public TreeNode TrimBST(TreeNode root, int low, int high) +{ + if (root == null) return null; + if (root.val < low) + return TrimBST(root.right, low, high); + + if (root.val > high) + return TrimBST(root.left, low, high); + + root.left = TrimBST(root.left, low, high); + root.right = TrimBST(root.right, low, high); + return root; +} +```