You are viewing a single comment's thread. Return to all comments →
python 3
def closestNumbers(arr): arr.sort() mindif = arr[-1] - arr[0] results = [] for i in range(len(arr) - 1): diff = arr[i + 1] - arr[i] if diff < mindif: mindif = diff + 0 results = [arr[i], arr[i + 1]] elif diff == mindif: results.append(arr[i]) results.append(arr[i + 1]) return results
Seems like cookies are disabled on this browser, please enable them to open this website
Closest Numbers
You are viewing a single comment's thread. Return to all comments →
python 3