Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Merge Intervals as a Generator Version solution in Speedy category for Merge Intervals by Stensen
def merge_intervals(intervals):
if not intervals: return []
intervals = sorted(intervals)
L, H = intervals[0]
for l, h in intervals[1:]:
if l - H == 1: H = h
elif l <= H: H = max(H, h)
else: yield L, H; L, H = l, h
yield L, H
Oct. 9, 2020