Leetcode 252 Meeting Rooms
程序员文章站
2022-03-11 21:49:36
...
思路: 这道题就是求各个区间有没有overlapping。先sort,然后遍历矩阵看各数组是否有overlapping。这边唯一需要学习一下的就是二维数组如何按第一维数字sort。直接展示代码:
class Solution {
public boolean canAttendMeetings(int[][] intervals) {
// 按第一维排序
Arrays.sort(intervals, (o1, o2) -> o1[0] - o2[0]);
for(int i = 0; i < intervals.length - 1; i++){
if(intervals[i][1] > intervals[i + 1][0]) return false;
}
return true;
}
}
总结:
- 与56,57是一个bundle,放一起一起看
推荐阅读
-
【leetcode】252 会议室(数组)
-
【LeetCode(Java) - 252】会议室
-
LeetCode Top 100 Liked Questions 253. Meeting Rooms II (Java版; Medium)
-
LeetCode 252. 会议室(排序)
-
【leetcode】841. Keys and Rooms
-
leetcode253——Meeting Rooms II
-
[Leetcode]253. Meeting Rooms II
-
LC.253. Meeting Rooms II
-
[Leetcode] 296. Best Meeting Point
-
Leetcode 253 Meeting Rooms II