# class Interval:
# def __init__(self, a=0, b=0):
# self.start = a
# self.end = b
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param intervals Interval类一维数组
# @return Interval类一维数组
#
class Solution:
def merge(self , intervals: List[Interval]) -> List[Interval]:
# write code here
new = sorted(intervals, key=lambda x: x.start)
if not intervals:
return []
s = new[0].start
e = new[0].end
r = []
for i, x in enumerate(new):
if i == new.__len__() - 1:
r.append(Interval(s, e))
else:
if e < new[i+1].start and e < new[i+1].end:
r.append(Interval(s, e))
s = new[i+1].start
e = new[i+1].end
else:
e = max(new[i+1].end, e)
return r