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 RoomsLeetCodeOOM
- [LintCode/LeetCode] Meeting RoomsLeetCodeOOM
- leetcode-252-Meeting RoomsLeetCodeOOM
- LeetCode252 Meeting RoomsLeetCodeOOM
- Leetcode 252. Meeting Room 253. Meeting Room IILeetCodeOOM
- [Leetcode]253. Meeting Rooms IILeetCodeOOM
- Leetcode 253:Meeting Rooms II(超詳細的解法!!!)LeetCodeOOM
- 253. Meeting Rooms IIOOM
- 【LeetCode】253. Meeting Rooms II 解題報告(C++)LeetCodeOOMC++
- LeetCode—253.會議室 II(Meeting Rooms II)——分析及程式碼(C++)LeetCodeOOMC++
- Leetcode 253: meeting roomLeetCodeOOM
- LeetCode 252. 會議室(排序)LeetCode排序
- Leetcode(easy heap)LeetCode
- LeetCode-EasyLeetCode
- Leetcode Meeting room問題系列 - 2LeetCodeOOM
- Leetcode Meeting room問題系列 - 1LeetCodeOOM
- LeetCode 198. 打家劫舍(Easy)LeetCode
- Leetcode - Tree - Easy(100-110)LeetCode
- LeetCode - Easy - 66. Plus OneLeetCode
- 【BUUCTF】Easy JavaJava
- Leetcode-Easy 70. Climbing StairsLeetCodeAI
- LeetCode - Easy - 206. Reverse Linked ListLeetCode
- 【LeetCode】290. Word Pattern 單詞規律(Easy)(JAVA)每日一題LeetCodeJava每日一題
- leetcode 掃描線專題 06-leetcode.252 meeting room 力扣.252 會議室LeetCodeOOM力扣
- C# 寫 LeetCode easy #14 Longest Common PrefixC#LeetCode
- [RoarCTF 2019]Easy Java 1Java
- leetcode231 2的冪(JAVA版)LeetCodeJava
- [LeetCode-SQL-Easy]176. 第二高薪水LeetCodeSQL高薪
- Java規則引擎 Easy RulesJava
- j-easy/easy-rules: Java簡單的規則引擎Java
- LeetCode 連結串列解題彙總 Java版LeetCodeJava
- 綜合練習——洗牌發牌Easy版
- leetcode演算法題解(Java版)-3-廣搜+HashMapLeetCode演算法JavaHashMap
- 高效翻譯軟體:Easy Translator for mac 中文版Mac
- leetcode演算法題解(Java版)-9-N皇后問題LeetCode演算法Java
- leetcode演算法題解(Java版)-12-中序遍歷LeetCode演算法Java
- leetcode:字串相乘(java)LeetCode字串Java
- leetcode 455題 javaLeetCodeJava