123
返回列表 发新帖
楼主: kemeng1314
跳转到指定楼层
上一主题 下一主题
收起左侧

facebook 新鲜电面

🔗
CiDut 2016-6-10 13:32:45 | 只看该作者
全局:
楼主加油         
回复

使用道具 举报

🔗
chijuzipi 2016-6-17 11:26:46 | 只看该作者
全局:
楼主有消息了么?等着报offer啊!
回复

使用道具 举报

🔗
 楼主| kemeng1314 2016-6-17 11:31:11 | 只看该作者
全局:
chijuzipi 发表于 2016-6-17 11:26
楼主有消息了么?等着报offer啊!

前天要了reference,还在等结果。
回复

使用道具 举报

🔗
 楼主| kemeng1314 2016-6-17 11:31:32 | 只看该作者
全局:

多谢鼓励!
回复

使用道具 举报

🔗
cicean 2016-9-8 06:23:18 | 只看该作者
全局:
56. Merge Intervals
这题?

补充内容 (2016-9-8 06:24):
不是的话难道是 merge K sort array?
回复

使用道具 举报

🔗
qiuxuxing007 2016-9-27 02:48:21 | 只看该作者
全局:
我觉得就是lc merge k sorted list .
回复

使用道具 举报

🔗
qiuxuxing007 2016-9-27 02:56:14 | 只看该作者
全局:
iterator其实就是lc里面的listnode 换汤不换药啊
回复

使用道具 举报

🔗
Ruby2333 2017-9-13 21:40:17 | 只看该作者
全局:
  1. import java.util.*;

  2. class QueueNode {
  3.         int value, array, index;
  4.         public QueueNode(int array, int index, int value) {
  5.                 this.array = array;
  6.                 this.index = index;
  7.                 this.value = value;
  8.         }
  9. }
  10. public class SortedKArrays {
  11.         private PriorityQueue<QueueNode> pq;
  12.         private int[][] arrays;
  13.        
  14.         public SortedKArrays(int[][] arrays) {
  15.                 this.arrays = arrays;
  16.                 int k = arrays.length;
  17.                
  18.                 pq = new PriorityQueue<>(k, new Comparator<QueueNode>() {
  19.                         @Override
  20.                         public int compare(QueueNode a, QueueNode b) {
  21.                                 return a.value - b.value;
  22.                         }
  23.                 });
  24.                
  25.                 for (int i = 0; i < k; i++) {
  26.                         if (arrays[i].length > 1) {
  27.                                 pq.offer(new QueueNode(i, 0, arrays[i][0]));
  28.                         }
  29.                 }
  30.         }
  31.         public boolean hasNext() {
  32.                 return !pq.isEmpty();
  33.         }
  34.         public int next() {
  35.                 QueueNode cur = pq.poll();
  36.                 int newIndex = cur.index + 1;
  37.                 if (newIndex < arrays[cur.array].length) {
  38.                         pq.offer(new QueueNode(cur.array, newIndex, arrays[cur.array][newIndex]));
  39.                 }
  40.                 return cur.value;
  41.                
  42.         }
  43.         public static void main(String[] args) {
  44.                 int[][] arrays = {{1, 4, 5}, {2, 7, 10}, {2, 4}, {2, 3}, {2, 8}};
  45.                 SortedKArrays sa = new SortedKArrays(arrays);
  46.                 while (sa.hasNext()) {
  47.                         System.out.println(sa.next());
  48.                 }
  49.         }
  50. }
复制代码
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表