Problem
Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), determine if a person could attend all meetings.
ExampleGiven intervals = [[0,30],[5,10],[15,20]], return false.
Note两次循环遍历
Solutionpublic class Solution { /** * @param intervals: an array of meeting time intervals * @return: if a person could attend all meetings */ public boolean canAttendMeetings(ListUpdate 2018-10intervals) { // Write your code here int size = intervals.size(); for (int i = 0; i < size-1; i++) { Interval a = intervals.get(i); for (int j = i+1; j < size; j++) { Interval b = intervals.get(j); if ((a.start > b.start && a.start < b.end) || (b.start > a.start && b.start < a.end)) { return false; } } } return true; } }
class Solution { public boolean canAttendMeetings(Interval[] intervals) { if (intervals == null || intervals.length < 2) return true; Listlist = Arrays.asList(intervals); Collections.sort(list, (a, b)->a.start-b.start); Interval pre = list.get(0); for (int i = 1; i < list.size(); i++) { if (list.get(i).start < pre.end) return false; else pre = list.get(i); } return true; } }
文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。
转载请注明本文地址:https://www.ucloud.cn/yun/71341.html
Problem A group of two or more people wants to meet and minimize the total travel distance. You are given a 2D grid of values 0 or 1, where each 1 marks the home of someone in the group. The distance ...
摘要:思路这道题就是要找区间之间是否有。而的复杂度是,所以最后总的复杂度为。思路的条件依然是不同的是这题需要求房间数。还是先,指向之前有的最小的那一个。接着的是,比小,所以又放入。。的是,比大,因此出,放入。。 Meeting Rooms Given an array of meeting time intervals consisting of start and end times [[...
Problem Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei), find the minimum number of conference rooms required. Example 1: Input: [[0, 30],[5,...
摘要:排序法复杂度时间空间思路这题和很像,我们按开始时间把这些都给排序后,就挨个检查是否有冲突就行了。有冲突的定义是开始时间小于之前最晚的结束时间。这里之前最晚的结束时间不一定是上一个的结束时间,所以我们更新的时候要取最大值。 Meeting Rooms Given an array of meeting time intervals consisting of start and end...
Problem Given a string s and a dictionary of words dict, determine if s can be break into a space-separated sequence of one or more dictionary words. Example Given s = lintcode, dict = [lint, code]. R...
阅读 1049·2021-11-22 15:35
阅读 1684·2021-10-26 09:49
阅读 3230·2021-09-02 15:11
阅读 2074·2019-08-30 15:53
阅读 2635·2019-08-30 15:53
阅读 2916·2019-08-30 14:11
阅读 3527·2019-08-30 12:59
阅读 3240·2019-08-30 12:53