# Definition for an interval.
# class Interval(object):
# def __init__(self, s=0, e=0):
# self.start = s
# self.end = e
class Solution(object):
def insert(self, intervals, newInterval):
"""
:type intervals: List[Interval]
:type newInterval: Interval
:rtype: List[Interval]
"""
Len=len(intervals)
ans1=[]
MIN=newInterval.start
MAX=newInterval.end
ans3=[]
for i in range(Len):
if intervals[i].end<newInterval.start:
ans1.append(intervals[i])
elif intervals[i].start>newInterval.end:
ans3.append(intervals[i])
else:
MIN=min(MIN,intervals[i].start)
MAX=max(MAX,intervals[i].end)
ans1.append(Interval(MIN,MAX))
ans1.extend(ans3)
return ans1