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 59a0541 commit d966946Copy full SHA for d966946
merge-intervals/Chapse57.py
@@ -0,0 +1,15 @@
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
0 commit comments