/**
* 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 {
int res = Integer.MAX_VALUE;
TreeNode pre;
public int getMinimumDifference(TreeNode root) {
sub_iter(root);
return res;
}
public void sub_iter(TreeNode node){
if(node==null){
return;
}
sub_iter(node.left);
if(pre!=null && Math.abs(node.val-pre.val) < res){
res = Math.abs(node.val-pre.val);
}
pre = node;
sub_iter(node.right);
}
}