[LC] 252. Meeting Rooms

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 1:

Input: [[0,30],[5,10],[15,20]]
Output: false

Example 2:

Input: [[7,10],[2,4]]
Output: true

NOTE: input types have been changed on April 15, 2019. Please reset to default code definition to get new method signature.

class Solution {
    public boolean canAttendMeetings(int[][] intervals) {
        if (intervals == null || intervals.length == 0) {
            return true;
        }
        Arrays.sort(intervals, (a, b) -> a[0] - b[0]);
        for (int i = 1; i < intervals.length; i++) {
            if (intervals[i - 1][1] > intervals[i][0]) {
                return false;
            }
        }
        return true;
    }
}

原文地址:https://www.cnblogs.com/xuanlu/p/11879986.html

时间: 2024-10-29 10:32:29

[LC] 252. Meeting Rooms的相关文章

LeetCode 252. Meeting Rooms (会议室)

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. For example,Given [[0, 30],[5, 10],[15, 20]],return false. 题目标签:sort 这道题目给了我们一个array的会议时间,让我们

252. Meeting Rooms

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. For example,Given [[0, 30],[5, 10],[15, 20]],return false. 此题重点是理解题意,会议时间不可以存在交集. 其次,了解排序,即数组

[LeetCode#252] Meeting Rooms

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. For example,Given [[0, 30],[5, 10],[15, 20]],return false. Analysis: The problem is

[LeetCode] Meeting Rooms I &amp; II

Meeting Rooms 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. For example,Given [[0, 30],[5, 10],[15, 20]],return false. 1 /** 2 * Definition

[LeetCode] Meeting Rooms II 会议室之二

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. For example,Given [[0, 30],[5, 10],[15, 20]],return 2. 这道题是之前那道Meeting Rooms的拓展,那道题只让我们是

Leetcode 252, 253. Meeting Rooms

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. For example,Given [[0, 30],[5, 10],[15, 20]],return false. 所有meeting time按照start排序之后,逐个检查当前的s

253 Meeting Rooms II

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. For example, Given [[0, 30],[5, 10],[15, 20]], return 2. 看到区间求重叠的部分 , 就想到对区间排序(start, en

[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. For example,Given [[0, 30],[5, 10],[15, 20]],return 2. Analysis: This problem l

Meeting Rooms II -- LeetCode

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. For example,Given [[0, 30],[5, 10],[15, 20]],return 2. 思路:贪心. 将所有interval按照开始时间从早到晚排序.之后