Bound using min/max in Java


  • 0
    L
    private static int findMinDifference(TreeNode node, int min, int max)  {
         if (node == null) {
            if(min == Integer.MIN_VALUE || max == Integer.MAX_VALUE) {
              return Integer.MAX_VALUE;
          }     
          return Math.abs(max - min);
         }
         return Math.min(findMinDifference(node.left, min, node.val),
            findMinDifference(node.right, node.val, max));
        }
    

Log in to reply
 

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