You are viewing a single comment's thread. Return to all comments →
Arrays.sort(arr); int minimumDifference = Integer.MAX_VALUE; for (int i = 0; i < arr.length - 1; i++) { int difference = arr[i + 1] - arr[i]; if (difference < minimumDifference) { minimumDifference = difference; if (minimumDifference == 0) { return 0; } } } return minimumDifference;
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Absolute Difference in an Array
You are viewing a single comment's thread. Return to all comments →