File tree Expand file tree Collapse file tree 6 files changed +86
-0
lines changed Expand file tree Collapse file tree 6 files changed +86
-0
lines changed Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for an interval.
3
+ * public class Interval {
4
+ * int start;
5
+ * int end;
6
+ * Interval() { start = 0; end = 0; }
7
+ * Interval(int s, int e) { start = s; end = e; }
8
+ * }
9
+ */
10
+ public class Solution {
11
+
12
+ static class RoomAllocator {
13
+
14
+ List <Interval > rooms = new ArrayList <>();
15
+
16
+ int currentTime = -1 ;
17
+
18
+ void alloc (Interval room ){
19
+ for (int i = 0 ; i < rooms .size (); i ++){
20
+ if (rooms .get (i ).end <= currentTime ){
21
+ rooms .set (i , room );
22
+ return ;
23
+ }
24
+ }
25
+
26
+ rooms .add (room );
27
+ }
28
+
29
+ void freeBefore (int time ){
30
+ currentTime = time ;
31
+ }
32
+ }
33
+
34
+ public int minMeetingRooms (Interval [] intervals ) {
35
+ Arrays .sort (intervals , (a , b ) -> a .start - b .start );
36
+
37
+ RoomAllocator ra = new RoomAllocator ();
38
+
39
+ for (Interval i : intervals ){
40
+ ra .freeBefore (i .start );
41
+ ra .alloc (i );
42
+ }
43
+
44
+ return ra .rooms .size ();
45
+ }
46
+ }
Original file line number Diff line number Diff line change
1
+ ---
2
+ layout : solution
3
+ title : Meeting Rooms II
4
+ date : 2015-08-12 20:03:46+08:00
5
+ leetcode_id : 253
6
+ ---
7
+ {% include_relative README.md %}
Original file line number Diff line number Diff line change
1
+ /**
2
+ * Definition for an interval.
3
+ * public class Interval {
4
+ * int start;
5
+ * int end;
6
+ * Interval() { start = 0; end = 0; }
7
+ * Interval(int s, int e) { start = s; end = e; }
8
+ * }
9
+ */
10
+ public class Solution {
11
+ public boolean canAttendMeetings (Interval [] intervals ) {
12
+ Arrays .sort (intervals , (a , b ) -> a .start - b .start );
13
+
14
+ int maxend = 0 ;
15
+
16
+ for (Interval i : intervals ){
17
+ if (i .start < maxend ){
18
+ return false ;
19
+ }
20
+
21
+ maxend = Math .max (maxend , i .end );
22
+ }
23
+
24
+ return true ;
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ ---
2
+ layout : solution
3
+ title : Meeting Rooms
4
+ date : 2015-08-12 20:02:37+08:00
5
+ leetcode_id : 252
6
+ ---
7
+ {% include_relative README.md %}
You can’t perform that action at this time.
0 commit comments