美文网首页
530. Minimum Absolute Difference

530. Minimum Absolute Difference

作者: littleDinosaur | 来源:发表于2017-03-23 22:08 被阅读0次
/**
 * 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