1200. 最小绝对差
为保证权益,题目请参考 1200. 最小绝对差(From LeetCode).
解决方案1
Python
python
# 1200. 最小绝对差
# https://leetcode.cn/problems/minimum-absolute-difference/
from typing import List
class Solution:
def minimumAbsDifference(self, arr: List[int]) -> List[List[int]]:
arr.sort()
sub_dis = float('inf')
for i in range(len(arr) - 1):
if abs(arr[i + 1] - arr[i]) < sub_dis:
sub_dis = abs(arr[i + 1] - arr[i])
ans = []
for i in range(len(arr) - 1):
if abs(arr[i + 1] - arr[i]) == sub_dis:
ans.append([arr[i], arr[i + 1]])
return ans
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22