LeetCode 252. Meeting Rooms (Java版; Easy)
welcome to my blog
LeetCode Top 100 Liked Questions 252. Meeting Rooms (Java版; Easy)
題目描述
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
如果區間有重合就不能參加會議; 核心: 將時間段按照開始時間排序, 然後遍歷陣列, 判斷相鄰兩個時間段之間是否有重疊
//如果區間有重合就不能參加所有會議
class Solution {
public boolean canAttendMeetings(int[][] intervals) {
//按照開始時間升序排序
Arrays.sort(intervals, (a,b)->a[0]-b[0]);
//從第二個時間段開始遍歷, 判斷相鄰兩個時間段之間是否有重疊
for(int i=1; i<intervals.length; i++){
//如果當前時間段的開始時間小於上一個時間段的結束時間, 說明區間有重合, 返回false
if(intervals[i][0] < intervals[i-1][1])
return false;
}
return true;
}
}
相關文章
- Leetcode 252. Meeting Rooms (Easy) (cpp)LeetCodeOOM
- 252. Meeting RoomsOOM
- LeetCode 252. Meeting Rooms(會議室)LeetCodeOOM
- [leetcode] 252. Meeting Rooms 解題報告LeetCodeOOM
- Leetcode: Meeting RoomsLeetCodeOOM
- LeetCode #252 - Meeting RoomsLeetCodeOOM
- Leetcode 252 Meeting RoomsLeetCodeOOM
- [LeetCode 252] Meeting RoomsLeetCodeOOM
- LeetCode252 Meeting RoomsLeetCodeOOM
- leetcode-252-Meeting RoomsLeetCodeOOM
- LeetCode-Meeting Rooms IILeetCodeOOM
- [LeetCode 253] Meeting Rooms IILeetCodeOOM
- *LeetCode-Meeting Rooms IILeetCodeOOM
- Leetcode 252. Meeting Room 253. Meeting Room IILeetCodeOOM
- [LintCode/LeetCode] Meeting RoomsLeetCodeOOM
- [Leetcode]253. Meeting Rooms IILeetCodeOOM
- [LeetCode] Meeting Rooms 會議室LeetCodeOOM
- LeetCode 題解(254) : Meeting RoomsLeetCodeOOM
- [LeetCode253]Meeting Rooms IILeetCodeOOM
- Meeting Rooms IIOOM
- LeetCode 253. Meeting Rooms II(會議室)LeetCodeOOM
- 253. Meeting Rooms IIOOM
- Leetcode 253:Meeting Rooms II(超詳細的解法!!!)LeetCodeOOM
- [Leetcode] 253. Meeting Rooms II 解題報告LeetCodeOOM
- 【LeetCode】253. Meeting Rooms II 解題報告(C++)LeetCodeOOMC++
- Facebook面試題 meeting rooms 求同時最多meeting room的時間面試題OOM
- LeetCode—253.會議室 II(Meeting Rooms II)——分析及程式碼(C++)LeetCodeOOMC++
- LeetCode 252. 會議室(排序)LeetCode排序
- Leetcode 253: meeting roomLeetCodeOOM
- LeetCode-EasyLeetCode
- Leetcode(easy heap)LeetCode
- LeetCode-Best Meeting PointLeetCode
- 【BUUCTF】Easy JavaJava
- 【leetcode】length of last word (easy)LeetCodeAST
- Leetcode Meeting room問題系列 - 2LeetCodeOOM
- Leetcode Meeting room問題系列 - 1LeetCodeOOM
- LeetCode - Easy - 66. Plus OneLeetCode
- LeetCode 198. 打家劫舍(Easy)LeetCode