You are viewing a single comment's thread. Return to all comments →
Here is my Python solution!
def closestNumbers(arr): arr = sorted(arr) lowest = float("inf") minimum = [] for i in range(len(arr) - 1): if arr[i + 1] - arr[i] < lowest: lowest = arr[i + 1] - arr[i] minimum = [arr[i], arr[i + 1]] elif arr[i + 1] - arr[i] == lowest: minimum.append(arr[i]) minimum.append(arr[i + 1]) return minimum
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 →
Here is my Python solution!