leetcode530

时间:2022-07-13 21:03:19
/**
* Definition for a binary tree node.
* public class TreeNode {
* public int val;
* public TreeNode left;
* public TreeNode right;
* public TreeNode(int x) { val = x; }
* }
*/
public class Solution {
List<int> list = new List<int>();
void postOrder(TreeNode Node)
{
if (Node != null)
{
list.Add(Node.val);
}
if (Node != null && Node.left != null)
{
postOrder(Node.left);
}
if (Node != null && Node.right != null)
{
postOrder(Node.right);
}
} public int GetMinimumDifference(TreeNode root)
{
postOrder(root); list = list.OrderBy(x => x).ToList();
var min = Int32.MaxValue;
for (int i = ; i < list.Count - ; i++)
{
min = Math.Min(min, Math.Abs(list[i] - list[i + ]));
}
Console.WriteLine(min);
return min;
}
}

https://leetcode.com/problems/minimum-absolute-difference-in-bst/#/description

相关文章