寻找第k小的数对
You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.
题目描述
数对 (a,b)
由整数 a
和 b
组成,其数对距离定义为 a
和 b
的绝对差值。
面对一个整数数组 nums
和一个整数 k
,数对由 nums[i]
和 nums[j]
组成且满足 。 希望你能帮她计算 所有数对距离中 第 k
小的数对距离。
输入格式
输入两行,第一行为,,表示有个数字,第小的数对距离。
第二行是个数字。
输出格式
输出第小的数对距离是多少
样例1:
3 1
1 3 1
0
样例2:
3 3
1 6 1
5
样例 1 解释
输入:nums = [1,3,1], k = 1
输出:0
解释:数对和对应的距离如下:
(1,3) -> 2
(1,1) -> 0
(3,1) -> 2
距离第 1 小的数对是 (1,1) ,距离为 0 。