forked from DaleStudy/leetcode-study
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjaejeong1.java
32 lines (27 loc) ยท 841 Bytes
/
jaejeong1.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.List;
// Definition of Interval:
class Interval {
int start, end;
Interval(int start, int end) {
this.start = start;
this.end = end;
}
}
public class Solution {
/**
* @param intervals: an array of meeting time intervals
* @return: if a person could attend all meetings
*/
public boolean canAttendMeetings(List<Interval> intervals) {
// ํ์ด: ์ ๋ ฌ ํ ์์์ ๋น๊ตํด๊ฐ๋ฉฐ ์กฐ๊ฑด์ ๋ง์ง ์์ผ๋ฉด false ๋ฅผ ๋ฐํํ๋ค.
// TC: O(N)
// SC: O(1)
var sortedIntervals = intervals.stream().sorted().toList();
for (int i=0; i<sortedIntervals.size()-1; i++) {
if (sortedIntervals.get(i).end > sortedIntervals.get(i+1).start) {
return false;
}
}
return true;
}
}