Given an array of meeting time intervals consisting of start and end times [s1, e1], [s2, e2], …, determine if a person could attend all meetings without overlap.
Input:
An array of meeting intervals where each interval is represented as [start, end].
Example 1:
meetings = [[0, 30], [5, 10], [15, 20]]
Output:
false
Because the person has overlapping meetings (for example, [0, 30] and [5, 10] overlap).
这道题本质上是判断区间是否存在重叠:把所有会议按开始时间排序后,只要发现某个会议的开始时间小于前一个会议的结束时间,就说明无法同时参加。最直接的做法是先排序,再线性扫描比较相邻区间,时间复杂度为 O(n log n),空间复杂度通常为 O(1) 或取决于排序实现。示例 [[0, 30], [5, 10], [15, 20]] 中,0 到 30 的会议与后面的会议重叠,因此结果为 false。