Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
except StopIteration: solution in Clear category for Merge Intervals (iterator version) by flpo
def merge_intervals(intervals):
try: a0, b0 = next(intervals)
except StopIteration: return
for a, b in intervals:
if a > b0 + 1:
yield a0, b0
a0, b0 = a, b
elif b0 < b:
b0 = b
yield a0, b0
Sept. 6, 2018