-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy path56.py
More file actions
23 lines (22 loc) · 654 Bytes
/
56.py
File metadata and controls
23 lines (22 loc) · 654 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Definition for an interval.
# class Interval:
# def __init__(self, s=0, e=0):
# self.start = s
# self.end = e
class Solution:
def merge(self, intervals):
"""
:type intervals: List[Interval]
:rtype: List[Interval]
"""
res = []
intervals.sort(key = lambda x: x.end)
for intr in intervals:
if not re:
res.append([intr.start, intr.end])
else:
s = intr.start
while res and res[-1][1] >= intr.start:
s = min(s, res.pop()[0])
res.append([s, intr.end])
return res