解析 56. Merge Intervals # approach 1 - elegent way (neetcode) # - time: O(nlogn) # - space: O(1) def merge(self, intervals: List[List[int]]) -> List[List[int]]: intervals.sort(key=lambda pair: pair[0]) res = [intervals[0]] for i in range(1, len(intervals)): interval = intervals[i] lastEnd = res[-1][1] if lastEnd >= interval[0]: # has overlap between the current interval and the previous added interval res[-1][1] = max(lastEnd, interval[1]) # merge else: # not has overlap
...