Easy Java Inorder Solution


  • 0
    E
    public class Solution {
        public int getMinimumDifference(TreeNode root) {
            int[] arr = {-1, Integer.MAX_VALUE};
            inorder(root, arr);
            return arr[1];
        }
        
        public void inorder(TreeNode root, int[] arr) {
            if(root == null) return;
            inorder(root.left,arr);
            if(arr[0] != -1) {
                arr[1] = Math.min(arr[1], Math.abs(arr[0] - root.val));
            }
            arr[0] = root.val;
            inorder(root.right,arr);
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.