国产xxxx99真实实拍_久久不雅视频_高清韩国a级特黄毛片_嗯老师别我我受不了了小说

資訊專欄INFORMATION COLUMN

[LintCode/LeetCode] Meeting Rooms

Noodles / 1907人閱讀

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.

Example

Given intervals = [[0,30],[5,10],[15,20]], return false.

Note

兩次循環遍歷

Solution
public class Solution {
    /**
     * @param intervals: an array of meeting time intervals
     * @return: if a person could attend all meetings
     */
    public boolean canAttendMeetings(List intervals) {
        // 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;
    }
}
Update 2018-10
class Solution {
    public boolean canAttendMeetings(Interval[] intervals) {
        if (intervals == null || intervals.length < 2) return true;
        List list = 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

相關文章

  • [LintCode/LeetCode] Best Meeting Point

    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 ...

    morgan 評論0 收藏0
  • Meeting Rooms & Meeting Rooms II

    摘要:思路這道題就是要找區間之間是否有。而的復雜度是,所以最后總的復雜度為。思路的條件依然是不同的是這題需要求房間數。還是先,指向之前有的最小的那一個。接著的是,比小,所以又放入。。的是,比大,因此出,放入。。 Meeting Rooms Given an array of meeting time intervals consisting of start and end times [[...

    TalkingData 評論0 收藏0
  • [LeetCode] 253. Meeting Rooms II

    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,...

    mengera88 評論0 收藏0
  • [Leetcode] Meeting Rooms 會議室

    摘要:排序法復雜度時間空間思路這題和很像,我們按開始時間把這些都給排序后,就挨個檢查是否有沖突就行了。有沖突的定義是開始時間小于之前最晚的結束時間。這里之前最晚的結束時間不一定是上一個的結束時間,所以我們更新的時候要取最大值。 Meeting Rooms Given an array of meeting time intervals consisting of start and end...

    jubincn 評論0 收藏0
  • [LintCode/LeetCode] Word Break

    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...

    dunizb 評論0 收藏0

發表評論

0條評論

Noodles

|高級講師

TA的文章

閱讀更多
最新活動
閱讀需要支付1元查看
<