class Solution(object):
def merge(self, intervals):
"""
:type intervals: List[Interval]
:rtype: List[Interval]
"""
if not intervals:
return []
res = []
intervals.sort(key=lambda x:x.start)
temp = intervals[0]
for i in range(len(intervals)-1):
if temp.end < intervals[i+1].start:
res.append(temp)
temp = intervals[i+1]
else:
temp.end = max(temp.end,intervals[i+1].end)
res.append(temp)
return res
python leetcode 56. Merge Intervals
最新推荐文章于 2022-11-06 16:08:48 发布