You are viewing a single comment's thread. Return to all comments →
Python
def closestNumbers(arr): arr.sort() output = [] minimum = arr[1] - arr[0] for i in range(1, len(arr)): diff = arr[i] - arr[i-1] if diff == minimum: output.extend([arr[i-1], arr[i]]) if diff < minimum: minimum = diff output = [arr[i-1], arr[i]] return output
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