leetcode530

/**
 * 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 = 0; i < list.Count - 1; i++)
            {
                min = Math.Min(min, Math.Abs(list[i] - list[i + 1]));
            }
            Console.WriteLine(min);
            return min;
        }
}

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

原文地址:https://www.cnblogs.com/asenyang/p/6732329.html