252:会议室
This commit is contained in:
parent
76aff63c46
commit
a1add8f320
57
src/main/java/leetcode/editor/cn/MeetingRooms.java
Normal file
57
src/main/java/leetcode/editor/cn/MeetingRooms.java
Normal file
@ -0,0 +1,57 @@
|
||||
//给定一个会议时间安排的数组 intervals ,每个会议时间都会包括开始和结束的时间 intervals[i] = [starti, endi] ,请你判
|
||||
//断一个人是否能够参加这里面的全部会议。
|
||||
//
|
||||
//
|
||||
//
|
||||
// 示例 1:
|
||||
//
|
||||
//
|
||||
//输入:intervals = [[0,30],[5,10],[15,20]]
|
||||
//输出:false
|
||||
//
|
||||
//
|
||||
// 示例 2:
|
||||
//
|
||||
//
|
||||
//输入:intervals = [[7,10],[2,4]]
|
||||
//输出:true
|
||||
//
|
||||
//
|
||||
//
|
||||
//
|
||||
// 提示:
|
||||
//
|
||||
//
|
||||
// 0 <= intervals.length <= 10⁴
|
||||
// intervals[i].length == 2
|
||||
// 0 <= starti < endi <= 10⁶
|
||||
//
|
||||
// Related Topics 数组 排序 👍 117 👎 0
|
||||
|
||||
package leetcode.editor.cn;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
//252:会议室
|
||||
public class MeetingRooms {
|
||||
public static void main(String[] args) {
|
||||
Solution solution = new MeetingRooms().new Solution();
|
||||
// TO TEST
|
||||
}
|
||||
|
||||
//leetcode submit region begin(Prohibit modification and deletion)
|
||||
class Solution {
|
||||
public boolean canAttendMeetings(int[][] intervals) {
|
||||
Arrays.sort(intervals, Comparator.comparingInt(e -> e[0]));
|
||||
for (int i = 1; i < intervals.length; i++) {
|
||||
if(intervals[i][0]<intervals[i-1][1]){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
//leetcode submit region end(Prohibit modification and deletion)
|
||||
|
||||
}
|
28
src/main/java/leetcode/editor/cn/doc/content/MeetingRooms.md
Normal file
28
src/main/java/leetcode/editor/cn/doc/content/MeetingRooms.md
Normal file
@ -0,0 +1,28 @@
|
||||
<p>给定一个会议时间安排的数组 <code>intervals</code> ,每个会议时间都会包括开始和结束的时间 <code>intervals[i] = [start<sub>i</sub>, end<sub>i</sub>]</code> ,请你判断一个人是否能够参加这里面的全部会议。</p>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>示例 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>intervals = [[0,30],[5,10],[15,20]]
|
||||
<strong>输出</strong>:false
|
||||
</pre>
|
||||
|
||||
<p><strong>示例 2:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>输入:</strong>intervals = [[7,10],[2,4]]
|
||||
<strong>输出</strong>:true
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p><strong>提示:</strong></p>
|
||||
|
||||
<ul>
|
||||
<li><code>0 <= intervals.length <= 10<sup>4</sup></code></li>
|
||||
<li><code>intervals[i].length == 2</code></li>
|
||||
<li><code>0 <= start<sub>i</sub> < end<sub>i</sub> <= 10<sup>6</sup></code></li>
|
||||
</ul>
|
||||
<div><div>Related Topics</div><div><li>数组</li><li>排序</li></div></div><br><div><li>👍 117</li><li>👎 0</li></div>
|
Loading…
Reference in New Issue
Block a user