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