Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Naive solution in Clear category for Merge Intervals by obone
def merge_intervals(intervals):
"""
Merge overlapped intervals.
"""
if not intervals:
return []
(a, b), data = intervals[0], []
for x, y in intervals:
if a <= x <= b + 1:
b = max(b, y)
else:
data.append((a, b))
a, b, = x, y
data.append((a, b))
return data
Sept. 12, 2019