You have k
lists of sorted integers in ascending order. Find the smallest range that includes at least one number from each of the k
lists.
We define the range [a,b] is smaller than range [c,d] if b-a < d-c
or a < c
if b-a == d-c
.
Example 1:
Input:[[4,10,15,24,26], [0,9,12,20], [5,18,22,30]]
Output: [20,24]
Explanation:
List 1: [4, 10, 15, 24,26], 24 is in range [20,24].
List 2: [0, 9, 12, 20], 20 is in range [20,24].
List 3: [5, 18, 22, 30], 22 is in range [20,24].
Note:
k
<= 3500value of elements
<= 105.【原题地址参见: [LeetCode]632. Smallest Range】
难度:Hard
class dataRange{
String source;
int flag;
}
public class SmallestRange {
public static void main(String [] args){
int []l1 = {4,10,15,24,26};
int []l2 = {0,9,12,20};
int []l3 = {5,18,22,30};
int len1 = l1.length;
int len2 = l2.length;
int len3 = l3.length;
int i=0,len;
len = len1+len2+len3;
System.out.println("len:"+len1+" "+len2+" "+len3);
dataObj arrd[] = new dataObj[len];
for(i=0;ihmCur = new HashMap();
i = 0;
int iStart = 0;
while(i
import java.util.*;
public class ComparatorT implements Comparator{
@Override
public int compare(Object o1,Object o2){
int k1 = ((dataObj)o1).value;
int k2 = ((dataObj)o2).value;
if (k1 > k2){
return 1; //大于时返回1,小于时返回-1,表示正序;反过来是反序
}
else{
return -1;
}
}
}