MrainW's Home

All things come to those who wait!

0%

LeetCode 252. Meeting Rooms

Question

Given an array of meeting time intervals where intervals[i] = [starti, endi], determine if a person could attend all meetings.

https://leetcode.com/problems/meeting-rooms/

  • Solution1
1
2
3
4
5
6
7
8
9
10
class Solution {
public boolean canAttendMeetings(int[][] intervals) {
if (intervals.length == 1) return true;
Arrays.sort(intervals, (a, b) -> a[0] - b[0]);
for (int i = 1; i < intervals.length; i++) {
if (intervals[i][0] < intervals[i-1][1]) return false;
}
return true;
}
}

Complexity:

Time complexity: O( nlogn)

Space complexity: O(1)

Welcome to my other publishing channels