class Solution: def merge(self , intervals: List[Interval]) -> List[Interval]: # write code here if not intervals: return [] intervals.sort(key=lambda x : x.start) res = [intervals[0]] for i in range(1, len(intervals)): if intervals[i].end <= res[-1].end: continue elif intervals[i].start > res[-1].end: res.append(intervals[i]) else: res[-1].end = intervals[i].end return res