Update 530.二叉搜索树的最小绝对差,添加C#版
This commit is contained in:
parent
7aef42def8
commit
bc7f72cad7
|
|
@ -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">
|
||||
<a href="https://programmercarl.com/other/kstar.html" target="_blank">
|
||||
|
|
|
|||
Loading…
Reference in New Issue