user-0 提问: 关于链表的在线测试题，求牛人解答，赠分

回复:
user: user-1
content: 说个算法  假如List1、List2、List3......ListK     (1)将List1,List2,List3......ListN的头结点放在一起，构造为Pair[0]，找出 max, min,  range = max - min,Pair[0].min_pointer ={min的指针},Min_Range = range,Min_Index = 0    (2)for(i =0;K条链有一条还没结束,i++){          将Pair[i]中的min换为min->next,构造出Pair[i+1]找出 max, min,           range = max - min,Pair[i+1].min_pointer ={min的指针},          if(Min_Range > range)              {Min_Range = range,              Min_Index = i+1}                    }   (3)输出Pair[Min_Index]的元素及范围

user: user-2
content: mylist = [[5,9,15,25,36], [-1,3,4,18,50], [2,8,20,30,45]] sumlist = [] num = 0 index = 0 combine = [num, index]  minGap = 10000 tail = 0 front = 0  for sublist in mylist:     for i in sublist:         combine = (i, mylist.index(sublist))         sumlist.append(combine)   sumlist.sort()  loop = 0 while loop <= len(sumlist) - len(mylist):     firstVisit = True       #前两个元素index相同，必然不满足要求，但是中间两个连续相同的就可以     flag = [0] * len(mylist)          add = 0     while 0 in flag:         num = sumlist[loop + add][0]         seq = sumlist[loop + add][1]         if firstVisit:             firstVisit = False             if seq == sumlist[loop + add + 1][1]:                 break            if flag[seq] == 0:             flag[seq] = 1         add += 1             add -= 1 #loop: index of tail, loop+add: index of head      if add > 0:         currentGap = sumlist[loop + add][0] - sumlist[loop][0]         if currentGap < minGap:             minGap = currentGap                         tail = loop             front = loop + add          loop += 1  print "minGap = " + str(minGap) print "front = " + str(front) print "tail = " + str(tail)  print sumlist for sublist in mylist:     print sublist

user: user-3
content: void getpair(int* list,int list count,int left bound,int right bound,vector<Int> Result){     For(int I=0;I<count;I++){             if(list[i] >left bound && list[i] <right bound )        Result.push_back(list[i]);   } }

user: user-4

user: user-5
content: 1) 把K个链表合起来,重新排序,并记录每个数值所在的链表序号. 2) 在新链表上找包含所有k个链表序号的最小子集, 计算每个子集的距离(最大的减去最小的),距离最小的就是答案.  以你的例子举例: 1) [(0,2),(3,3),(4,2),(5,1),(7,3),(8,1),....] 2) 子集[(3,3),(4,2),(5,1)] 5-3=2 最小.

user: user-6
content: 大众点评，同等

user: user-7
content: 大众点评，同等

user: user-8
content: 大牛在哪里？

user: user-9
content: 哈哈，大众点评测试呀

user: user-0
content: 等待大牛出现，谢谢了

user: user-10
content: 六楼的答案可行，暂时想不出更好的解决方法了，用它的方案写个程序吧  lst_lst = [     [5, 8, 15, 25, 36],     [0, 4, 18, 50],     [3, 7, 20, 30, 45], ]  count_map = [0,] * len(lst_lst)  all_in_lst = [] for i in range(len(lst_lst)):     all_in_lst += [{'value':a,'group':i} for a in lst_lst[i]]   all_in_lst.sort(key = lambda x: x['value'])  best_solve = []  result_lst = []  for t in all_in_lst:     result_lst.append(t)     count_map[t['group']] += 1      if 1 < len(result_lst):         if result_lst[0]['group'] == t['group']:             count_map[t['group']] -= 1             result_lst = result_lst[1:]                          while 1 < len(result_lst) and result_lst[0]['group'] == result_lst[1]['group']:                 result_lst = result_lst[1:]      if 0 not in count_map:         # 包含了所有列表中的至少一个元素         if [] == best_solve:             best_solve = result_lst[:]                              elif  (best_solve[-1]['value'] - best_solve[0]['value']) > (result_lst[-1]['value'] - result_lst[0]['value']):             best_solve = result_lst[:]  print(best_solve)