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

Google电面

🔗
waver 2016-4-2 10:56:03 | 只看该作者
全局:
是时间吗?  怎么会有27   33。。。
回复

使用道具 举报

🔗
newFeeling 2016-4-3 04:45:01 | 只看该作者
全局:
leetcode 原题
回复

使用道具 举报

🔗
wyb_1221 2016-4-3 06:56:18 | 只看该作者
全局:

可以给个leetcode连接吗?
回复

使用道具 举报

🔗
zdhzh05 2016-4-3 08:51:27 | 只看该作者
全局:
参考leetcode 56 Merge Intervals

思路:
合并schedule A,B(或更多)
sort
merge intervals 返回新的interval list
线性扫描一遍,找到第一个符合meeting长度的gap

Time: O((m+n)log(m+n)) + O(m+n)
Space: O(m+n)

public int getMeetingStartTime(List<Interval> listA, List<Interval> listB, int limit) {
        if (listA == null && listB == null) return 0;
        List<Interval> list = new ArrayList<Interval>();
        if (listA != null) list.addAll(listA);
        if (listB != null) list.addAll(listB);
        if (list.size() == 0) return 0;
        Collections.sort(list, new Comparator<Interval>() {
                @Override
                public int compare(Interval i1, Interval i2) {
                        if (i1.start == i2.start) return i1.end-i2.end;
                        return i1.start-i2.start;
                }
        });
        Interval t = list.get(0);
        List<Interval> res = new ArrayList<Interval>();
        for (int i = 1; i < list.size(); i++) {
                Interval c = list.get(i);
                if (c.start <= t.end) {
                        t = new Interval(t.start, c.end);
                } else {
                        res.add(t);
                        t = c;
                }
        }
        res.add(t);
        for (int i = 1; i < res.size(); i++) {
                if (res.get(i).start-res.get(i-1).end >= limit) {
                        return res.get(i-1).end;
                }
        }
        return res.get(res.size()-1).end;
}

回复

使用道具 举报

🔗
newFeeling 2016-4-4 08:20:12 | 只看该作者
全局:
wyb_1221 发表于 2016-4-3 06:56
可以给个leetcode连接吗?

253. Meeting Rooms II
回复

使用道具 举报

🔗
Alice0701 2016-4-4 08:27:50 | 只看该作者
全局:
谢谢楼主分享!!感觉楼上说的merge interval的方法估计算最优的了?
回复

使用道具 举报

全局:
merge Intervals,然后查找cur_start_time - last_end_time > meeting_time
回复

使用道具 举报

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

本版积分规则

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