1
class Solution {
2
public int[] smallestRange(List<List<Integer>> nums) {
3
int[] res = {-100000, 100000};
4
PriorityQueue<int[]> pq = new PriorityQueue<>((a, b) -> a[0] - b[0]);
5
int max = Integer.MIN_VALUE;
6
int k = nums.size();
7

8
for (int i = 0; i < k; i++) {
9
int minElem = nums.get(i).get(0);
10
int[] arr = {minElem, 0, i};
11

12
max = Math.max(max, minElem);
13
pq.add(arr);
14
}
15
while (true) {
16
int min[] = pq.poll();
17
if (res[1] - res[0] > max - min[0]) {
18
res[1] = max;
19
res[0] = min[0];
20
}
21
min[1]++;
22

23
List<Integer> cur = nums.get(min[2]);
24

25
if (min[1] == cur.size()) {
26
break;
27
} else {
28
min[0] = cur.get(min[1]);
29
max = Math.max(max, cur.get(min[1]));
30
pq.add(min);
31
}
32
}
33
return res;
34
}
35
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0