Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
9-liner: Generator solution in Clear category for Merge Intervals (generator version) 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