Skip to content

Commit 91179a3

Browse files
author
wuduhren
committed
updates
1 parent 758ba68 commit 91179a3

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

problems/python3/merge-intervals.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
ans.append([s, e])
17+
return ans

0 commit comments

Comments
 (0)