[Swift]LeetCode252.会议室 $ 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.


给定由开始和结束时间[[s1,e1],[s2,e2],...] (si < ei)组成的一系列会议时间间隔,确定一个人是否可以参加所有会议。

例如,

给出[[0, 30],[5, 10],[15, 20]],

返回 false


 1 class Solution {
 2     func canAttendMeetings(_ intervals:[[Int]]) -> Bool {
 3         var intervals = intervals
 4         intervals.sort(by: {(arr1:[Int],arr2:[Int]) -> Bool in
 5                     return arr1.first! < arr2.first!})
 6         for i in 1..<intervals.count
 7         {
 8             if intervals[i].first! < intervals[i - 1].last!
 9             {
10                 return false
11             }
12         }
13         return true
14     }
15 }

猜你喜欢

转载自www.cnblogs.com/strengthen/p/10218004.html
今日推荐