package leetcode;

/**
 * https://leetcode.com/problems/minimum-absolute-difference-in-bst/
 */
public class Problem530 {
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    public int getMinimumDifference(TreeNode root) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem530 prob = new Problem530();

        TreeNode root = new TreeNode(1);
        root.right = new TreeNode(3);
        root.right.left = new TreeNode(2);

        System.out.println(prob.getMinimumDifference(root)); // 1
    }
}

@@ -344,15 +344,85 @@
     
-// TODO
+MinDiff minDiff = new MinDiff();%0A        getMinimumDifference(root, minDiff);
 %0A   
@@ -433,17 +433,27 @@
  return 
-0
+minDiff.min
 ;%0A    %7D%0A
@@ -458,29 +458,30 @@
 %7D%0A%0A    p
-ublic
+rivate
  static 
 void mai
@@ -476,268 +476,491 @@
 tic 
-void main(String%5B%5D args) %7B%0A        Problem530 prob = new Problem530();%0A
+class MinDiff %7B%0A        TreeNode node;%0A        int min = Integer.MAX_VALUE;
 %0A    
+%7D%0A%0A
     
-TreeNode root = new TreeNode(1);%0A        root.right = new TreeNode(3);%0A        root.right.left = new TreeNode(2);%0A%0A        System.out.println(prob.getMinimumDifference(root)); // 1
+private static void getMinimumDifference(TreeNode node, MinDiff minDiff) %7B%0A        if (node == null) %7B%0A            return;%0A        %7D%0A        getMinimumDifference(node.left, minDiff);%0A        if (minDiff.node != null) %7B%0A            minDiff.min = Math.min(minDiff.min, Math.abs(minDiff.node.val - node.val));%0A        %7D%0A        minDiff.node = node;%0A        getMinimumDifference(node.right, minDiff);
 %0A   

Solve problem 530