You are viewing a single comment's thread. Return to all comments →
public static int minimumAbsoluteDifference(List<Integer> arr) { Collections.sort(arr); int min = Math.abs(arr.get(0) - arr.get(1)); for(int i = 0; i < arr.size() - 1; i++) { int diff = Math.abs(arr.get(i) - arr.get(i + 1)); if(diff == 0) { return diff; } if(diff < min) { min = diff; } } return min; }
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 →