一:题目
二:上码
/*** Definition for a binary tree node.* public class TreeNode {* int val;* TreeNode left;* TreeNode right;* TreeNode() {}* TreeNode(int val) { this.val = val; }* TreeNode(int val, TreeNode left, TreeNode right) {* this.val = val;* this.left = left;* this.right = right;* }* }*/
class Solution {public void Order (TreeNode root,List<Integer> list) {if (root == null) return ;Order(root.left,list);list.add(root.val); Order(root.right,list);}public int getMinimumDifference(TreeNode root) {List<Integer> list = new ArrayList<>();Order(root,list);int minn = Integer.MAX_VALUE;for (int i = 1; i < list.size(); i++) {minn = Math.min(minn,list.get(i) - list.get(i-1)); }return minn;}
}