1200. Minimum Absolute Difference
Python
class Solution:
def minimumAbsDifference(self, arr: List[int]) -> List[List[int]]:
if not arr:
return []
items = sorted(arr)
gap = None
results = []
for i in range(0, len(items)-1):
current_gap = items[i+1] - items[i]
if gap is None:
gap = current_gap
results.append([items[i], items[i+1]])
continue
if gap == current_gap:
results.append([items[i], items[i+1]])
continue
if gap > current_gap:
gap = current_gap
results = [[items[i], items[i+1]]]
return results