Skip to content

Commit caf5774

Browse files
authoredDec 25, 2021
Create 56-Merge-Intervals.py
1 parent 99633e9 commit caf5774

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed
 

‎56-Merge-Intervals.py

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

0 commit comments

Comments
 (0)
Please sign in to comment.