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; } }
文章版權歸作者所有,未經允許請勿轉載,若此文章存在違規行為,您可以聯系管理員刪除。
轉載請注明本文地址:http://specialneedsforspecialkids.com/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...
閱讀 1050·2021-11-22 15:35
閱讀 1685·2021-10-26 09:49
閱讀 3230·2021-09-02 15:11
閱讀 2075·2019-08-30 15:53
閱讀 2636·2019-08-30 15:53
閱讀 2917·2019-08-30 14:11
閱讀 3527·2019-08-30 12:59
閱讀 3241·2019-08-30 12:53