File tree Expand file tree Collapse file tree 3 files changed +49
-0
lines changed
non-overlapping-intervals Expand file tree Collapse file tree 3 files changed +49
-0
lines changed Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def minMeetingRooms (self , intervals : List [List [int ]]) -> int :
3
+ if not intervals :
4
+ return 0
5
+
6
+ rooms_needed , end_pointer = 0 , 0
7
+
8
+ start_times = sorted ([interval [0 ] for interval in intervals ])
9
+ end_times = sorted ([interval [1 ] for interval in intervals ])
10
+
11
+ for i in range (len (start_times )):
12
+ if start_times [i ] >= end_times [end_pointer ]:
13
+ end_pointer += 1
14
+ else :
15
+ rooms_needed += 1
16
+
17
+ return rooms_needed
18
+
19
+ ## TC: O(nlogn), SC: O(n)
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def eraseOverlapIntervals (self , intervals : List [List [int ]]) -> int :
3
+ last_end = - math .inf
4
+ overlap_count = 0
5
+
6
+ sorted_intervals = sorted (intervals , key = lambda interval : interval [1 ])
7
+
8
+ for start , end in sorted_intervals :
9
+ if start >= last_end :
10
+ last_end = end
11
+ else :
12
+ overlap_count += 1
13
+
14
+ return overlap_count
15
+
16
+ ## TC: O(nlogn), SC: O(n)
Original file line number Diff line number Diff line change
1
+ class Solution :
2
+ def rotate (self , matrix : List [List [int ]]) -> None :
3
+ """
4
+ Do not return anything, modify matrix in-place instead.
5
+ """
6
+ matrix .reverse ()
7
+
8
+ n = len (matrix )
9
+
10
+ for i in range (n ):
11
+ for j in range (i + 1 , n ):
12
+ matrix [i ][j ], matrix [j ][i ] = matrix [j ][i ], matrix [i ][j ]
13
+
14
+ ## TC: O(n^2), SC: O(1)
You can’t perform that action at this time.
0 commit comments