File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Collections ;
2+ import java .util .List ;
3+
4+ /**
5+ * Definition of Interval:
6+ * public class Interval {
7+ * int start, end;
8+ * Interval(int start, int end) {
9+ * this.start = start;
10+ * this.end = end;
11+ * }
12+ * }
13+ */
14+
115public class Solution {
16+ /**
17+ * @param intervals: an array of meeting time intervals
18+ * @return: if a person could attend all meetings
19+ */
20+
21+ // 시간복잡도: O(n log n) - 정렬, 공간복잡도: O(1)
22+ public boolean canAttendMeetings (List <Interval > intervals ) {
23+ // Write your code here
24+
25+ if (intervals == null || intervals .isEmpty ()) return true ;
26+
27+ Collections .sort (intervals , (i1 , i2 ) -> i1 .start - i2 .start );
28+
29+ Interval previous = intervals .get (0 );
30+
31+ for (int i = 1 ; i < intervals .size (); i ++) {
32+ Interval current = intervals .get (i );
33+ if (previous .end > current .start ) {
34+ return false ;
35+ }
36+ previous = current ;
37+ }
38+
39+ return true ;
40+ }
241}
42+
You can’t perform that action at this time.
0 commit comments