[Swift]LeetCode253.会议室 II $ Meeting Rooms II
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公众号:山青咏芝(shanqingyongzhi)
➤博客园地址:山青咏芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:https://www.cnblogs.com/strengthen/p/10218124.html
➤如果链接不是山青咏芝的博客园地址,则可能是爬取作者的文章。
➤原文已修改更新!强烈建议点击原文地址阅读!支持作者!支持原创!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
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.
给定由开始和结束时间 [[s1,e1],[s2,e2],...] (si < ei)组成的一系列会议时间间隔,找出所需的最小会议室数。
例如,
给出 [[0, 30],[5, 10],[15, 20]],
返回2。
1 class Solution { 2 func canAttendMeetings(_ intervals:[[Int]]) -> Int { 3 var intervals = intervals 4 intervals.sort(by: {(arr1:[Int],arr2:[Int]) -> Bool in 5 return arr1.first! < arr2.first!}) 6 var q:[Int] = [Int]() 7 for a in intervals 8 { 9 if !q.isEmpty && q.last! <= a.first! 10 { 11 for (index, value) in q.enumerated() 12 { 13 if q.min() == value 14 { 15 q.remove(at: index) 16 break 17 } 18 } 19 } 20 q.append(a.last!) 21 } 22 return q.count 23 } 24 }