18 lines
635 B
Python
18 lines
635 B
Python
|
class Solution:
|
||
|
def merge(self, intervals: List[List[int]]) -> List[List[int]]:
|
||
|
sorted_intervals = sorted(intervals, key=lambda x:x[0])
|
||
|
cur_l = [sorted_intervals[0][0], sorted_intervals[0][1]]
|
||
|
rlt = []
|
||
|
for ind, l in enumerate(sorted_intervals[1:]):
|
||
|
|
||
|
if cur_l[1] >= l[1] and cur_l[0]<=l[0]:pass
|
||
|
elif cur_l[1] >= l[0]:
|
||
|
cur_l[1] = l[1]
|
||
|
else:
|
||
|
r = cur_l.copy()
|
||
|
rlt.append(r)
|
||
|
cur_l[0]=l[0]
|
||
|
cur_l[1]=l[1]
|
||
|
# print(cur_l,rlt)
|
||
|
rlt.append(cur_l)
|
||
|
return rlt
|