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
最新推荐文章于 2024-08-15 01:55:01 发布