示例 1:
输入:arr = [4,2,1,3] 输出:[[1,2],[2,3],[3,4]]
示例 2:
输入:arr = [1,3,6,10,15] 输出:[[1,3]]
示例 3:
输入:arr = [3,8,-10,23,19,-4,-14,27] 输出:[[-14,-10],[19,23],[23,27]]
提示:
2 <= arr.length <= 10^5 -10^6 <= arr[i] <= 10^6
程序代码
class Solution:
def minimumAbsDifference(self, arr: List[int]) -> List[List[int]]:
ans = 99999999
arr.sort()
for i in range(1, len(arr)):
if arr[i] - arr[i-1] < ans:
ans = arr[i] - arr[i-1]
ans1 = []
ans1.append([arr[i-1], arr[i]])
elif arr[i] -arr[i-1] == ans:
ans1.append([arr[i-1], arr[i]])
return ans1
|