Compare commits
3 commits
3e42548f95
...
14e8b539c6
Author | SHA1 | Date | |
---|---|---|---|
Bruno BELANYI | 14e8b539c6 | ||
Bruno BELANYI | 0f91c37d6d | ||
Bruno BELANYI | 1ce063154e |
|
@ -31,7 +31,8 @@ def merge_intervals(intervals: Iterable[Interval]) -> list[Interval]:
|
||||||
|
|
||||||
res = [intervals[0]]
|
res = [intervals[0]]
|
||||||
for candidate in intervals[1:]:
|
for candidate in intervals[1:]:
|
||||||
if res[-1].end >= candidate.start:
|
# Range is inclusive in both end, so add 1 to end in case of near miss
|
||||||
|
if (res[-1].end + 1) >= candidate.start:
|
||||||
new_end = max(res[-1].end, candidate.end)
|
new_end = max(res[-1].end, candidate.end)
|
||||||
res[-1] = Interval(res[-1].start, new_end)
|
res[-1] = Interval(res[-1].start, new_end)
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -31,7 +31,8 @@ def merge_intervals(intervals: Iterable[Interval]) -> list[Interval]:
|
||||||
|
|
||||||
res = [intervals[0]]
|
res = [intervals[0]]
|
||||||
for candidate in intervals[1:]:
|
for candidate in intervals[1:]:
|
||||||
if res[-1].end >= candidate.start:
|
# Range is inclusive in both end, so add 1 to end in case of near miss
|
||||||
|
if (res[-1].end + 1) >= candidate.start:
|
||||||
new_end = max(res[-1].end, candidate.end)
|
new_end = max(res[-1].end, candidate.end)
|
||||||
res[-1] = Interval(res[-1].start, new_end)
|
res[-1] = Interval(res[-1].start, new_end)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue