Skip to content

Commit 1dab177

Browse files
authored
Merge pull request #1267 from chapse57/main
[Chapese]2주차 Solution
2 parents 54bde43 + 7907479 commit 1dab177

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Diff for: merge-intervals/Chapse57.py

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution:
2+
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
3+
# O(nlogn)
4+
5+
intervals.sort(key = lambda i : i[0])
6+
output = [intervals[0]]
7+
8+
for start , end in intervals[1:]:
9+
lastEnd = output[-1][1] #last end value
10+
if start <= lastEnd:
11+
output[-1][1] = max(lastEnd, end)
12+
else:
13+
output.append([start, end])
14+
return output
15+
16+
17+
18+

0 commit comments

Comments
 (0)