File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ // Definition for an Interval.
3
+ class Interval {
4
+ public int start;
5
+ public int end;
6
+
7
+ public Interval() {}
8
+
9
+ public Interval(int _start, int _end) {
10
+ start = _start;
11
+ end = _end;
12
+ }
13
+ };
14
+ */
15
+
16
+ class Solution {
17
+ public List <Interval > employeeFreeTime (List <List <Interval >> schedule ) {
18
+ List <Interval > result = new ArrayList <>();
19
+
20
+ PriorityQueue <Interval > pq = new PriorityQueue <>(Comparator .comparing (i -> i .start ));
21
+ schedule .forEach (i -> pq .addAll (i ));
22
+
23
+ Interval prev = pq .poll ();
24
+
25
+ while (!pq .isEmpty ()) {
26
+ Interval curr = pq .poll ();
27
+
28
+ if (prev .end < curr .start ) {
29
+ result .add (new Interval (prev .end , curr .start ));
30
+ prev = curr ;
31
+ } else {
32
+ prev .end = Math .max (prev .end , curr .end );
33
+ }
34
+ }
35
+
36
+ return result ;
37
+ }
38
+ }
You can’t perform that action at this time.
0 commit comments