Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bc7f72c

Browse files
committed
Update 530.二叉搜索树的最小绝对差,添加C#版
1 parent 7aef42d commit bc7f72c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

‎problems/0530.二叉搜索树的最小绝对差.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,27 @@ impl Solution {
647647
}
648648
}
649649
```
650+
### C#
651+
```C#
652+
// 递归
653+
public class Solution
654+
{
655+
public List<int> res = new List<int>();
656+
public int GetMinimumDifference(TreeNode root)
657+
{
658+
Traversal(root);
659+
return res.SelectMany((x, i) => res.Skip(i + 1).Select(y => Math.Abs(x - y))).Min();
660+
661+
}
662+
public void Traversal(TreeNode root)
663+
{
664+
if (root == null) return;
665+
Traversal(root.left);
666+
res.Add(root.val);
667+
Traversal(root.right);
668+
}
669+
}
670+
```
650671

651672
<p align="center">
652673
<a href="https://programmercarl.com/other/kstar.html" target="_blank">

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /