题目如下:

解题思路:把arr排好序后依次求相邻两个元素的差值,即可得到结果。

代码如下:

class Solution(object):
    def minimumAbsDifference(self, arr):
        """
        :type arr: List[int]
        :rtype: List[List[int]]
        """
        arr.sort()
        res = []
        min_diff = float('inf')
        for i in range(len(arr)-1):
            if arr[i+1] - arr[i] < min_diff:
                res = [[arr[i],arr[i+1]]]
                min_diff = arr[i+1] - arr[i]
            elif arr[i+1] - arr[i] == min_diff:
                res.append([arr[i],arr[i+1]])
        return res
02-14 02:07