530. Minimum Absolute Difference
/**
* Definition for a binary tree node.
* public class TreeNode {
* int val;
* TreeNode left;
* TreeNode right;
* TreeNode(int x) { val = x; }
* }
*/
public class Solution {
public int min = Integer.MAX_VALUE ;
public int last = -1;
public void travel(TreeNode root){
if(root == null ){
return ;
}
travel(root.left);
if(last != -1){
min = Math.min(min , Math.abs(root.val - last));
}
last = root.val ;
travel(root.right);
}
public int getMinimumDifference(TreeNode root) {
travel(root);
return min;
}
}
本文标题:530. Minimum Absolute Difference
本文链接:https://www.haomeiwen.com/subject/nuztottx.html
网友评论