We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 758ba68 commit 91179a3Copy full SHA for 91179a3
1 file changed
problems/python3/merge-intervals.py
@@ -0,0 +1,17 @@
1
+"""
2
+Time: O(NLogN) for sorting
3
+Space: O(1) excluding the output.
4
5
+class Solution:
6
+ def merge(self, intervals: List[List[int]]) -> List[List[int]]:
7
+ ans = []
8
+ intervals.sort()
9
+
10
+ for s, e in intervals:
11
+ if not ans:
12
+ ans.append([s, e])
13
+ elif ans[-1][1]>=s:
14
+ ans[-1][1] = max(ans[-1][1], e)
15
+ else:
16
17
+ return ans
0 commit comments