看完示例直接上手敲,调了半天才发现是 类一维数组,笑死,根本通不过 :)
# class Interval: # def __init__(self, a=0, b=0): # self.start = a # self.end = b # # # @param intervals Interval类一维数组 # @return Interval类一维数组 # class Solution: def merge(self , intervals ): i, intervals = 0, sorted(intervals, key=lambda x: x.start) while i < len(intervals) - 1: if intervals[i].end >= intervals[i + 1].start: intervals[i].end = max(intervals[i].end, intervals.pop(i + 1).end) else: i += 1 return intervals