# 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]
"""
intervals.sort(key = lambda interval_tmp: interval_tmp.start)
N = len(intervals)
res = []
for i in range(N):
flag = 0
for j in range(len(res)):
if not (intervals[i].start > res[j].end or intervals[i].end < res[j].start):
res[j].start = min(intervals[i].start, res[j].start)
res[j].end = max(intervals[i].end, res[j].end)
flag = 1
break
if flag == 0:
res.append(intervals[i])
return res