We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b88a3df commit 2610d48Copy full SHA for 2610d48
insert-interval/pmjuu.py
@@ -0,0 +1,32 @@
1
+'''
2
+시간 복잡도: O(n)
3
+공간 복잡도: O(n)
4
5
+from typing import List
6
+
7
8
+class Solution:
9
+ def insert(self, intervals: List[List[int]], newInterval: List[int]) -> List[List[int]]:
10
+ n = len(intervals)
11
+ start, end = newInterval
12
+ i = 0
13
+ result = []
14
15
+ # before merging
16
+ while i < n and intervals[i][1] < start:
17
+ result.append(intervals[i])
18
+ i += 1
19
20
+ # merge
21
+ while i < n and intervals[i][0] <= end:
22
+ start = min(start, intervals[i][0])
23
+ end = max(end, intervals[i][1])
24
25
+ result.append([start, end])
26
27
+ # after merging
28
+ while i < n:
29
30
31
32
+ return result
0 commit comments