mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-08 08:50:15 +08:00
Update 530.二叉搜索树的最小绝对差,添加C#版
This commit is contained in:
@ -647,6 +647,27 @@ impl Solution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
### C#
|
||||||
|
```C#
|
||||||
|
// 递归
|
||||||
|
public class Solution
|
||||||
|
{
|
||||||
|
public List<int> res = new List<int>();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||||
|
Reference in New Issue
Block a user