""" Definition of Interval. class Interval(object): def __init__(self, start, end): self.start = start self.end = end """ classSolution: """ @param intervals: interval list. @return: A new interval list. """ defmerge(self, intervals): # write your code here # n log(n) intervals = sorted(intervals, key=lambda x: x.start) # + n i = 1 while i < len(intervals): if intervals[i].start < intervals[i-1].end and intervals[i].end < intervals[i-1].end: del intervals[i] continue if intervals[i].start <= intervals[i-1].end and intervals[i].end >= intervals[i-1].end: intervals[i-1].end = intervals[i].end del intervals[i] continue i += 1 return intervals