Skip to content

Commit f0fdcfc

Browse files
refactor 252
1 parent ea48b17 commit f0fdcfc

File tree

1 file changed

+13
-23
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+13
-23
lines changed

src/main/java/com/fishercoder/solutions/_252.java

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,31 @@
44

55
import java.util.ArrayList;
66
import java.util.Collections;
7-
import java.util.Comparator;
87
import java.util.List;
9-
/**Given an array of meeting time intervals consisting of start and end times [[s1,e1],[s2,e2],...] (si < ei),
10-
* determine if a person could attend all meetings.
118

12-
For example,
13-
Given [[0, 30],[5, 10],[15, 20]],
14-
return false.*/
159
public class _252 {
16-
public boolean canAttendMeetings(Interval[] intervals) {
10+
public static class Solution1 {
11+
public boolean canAttendMeetings(Interval[] intervals) {
1712

18-
List<Interval> list = new ArrayList();
19-
for (Interval interval : intervals) {
20-
list.add(interval);
21-
}
22-
23-
Collections.sort(list, new Comparator<Interval>() {
13+
List<Interval> list = new ArrayList();
14+
for (Interval interval : intervals) {
15+
list.add(interval);
16+
}
2417

25-
@Override
26-
public int compare(Interval o1, Interval o2) {
18+
Collections.sort(list, (o1, o2) -> {
2719
if (o1.start > o2.start) {
2820
return 1;
2921
} else {
3022
return -1;
3123
}
32-
}
24+
});
3325

34-
});
35-
36-
for (int i = 0; i < list.size() - 1; i++) {
37-
if (list.get(i).end > list.get(i + 1).start) {
38-
return false;
26+
for (int i = 0; i < list.size() - 1; i++) {
27+
if (list.get(i).end > list.get(i + 1).start) {
28+
return false;
29+
}
3930
}
31+
return true;
4032
}
41-
return true;
42-
4333
}
4434
}

0 commit comments

Comments
 (0)