★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★
➤微信公衆號:山青詠芝(shanqingyongzhi)
➤博客園地址:山青詠芝(https://www.cnblogs.com/strengthen/)
➤GitHub地址:https://github.com/strengthen/LeetCode
➤原文地址:http://www.javashuo.com/article/p-vgjxpwxo-mb.html
➤若是連接不是山青詠芝的博客園地址,則多是爬取做者的文章。
➤原文已修改更新!強烈建議點擊原文地址閱讀!支持做者!支持原創!
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★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.git
For example,
Given [[0, 30],[5, 10],[15, 20]],
return 2.github
給定由開始和結束時間 [[s1,e1],[s2,e2],...] (si < ei)組成的一系列會議時間間隔,找出所需的最小會議室數。微信
例如,app
給出 [[0, 30],[5, 10],[15, 20]],ui
返回2。spa
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 }