Compare commits

..

3 commits

Author SHA1 Message Date
Bruno BELANYI 3e42548f95 2022: d15: ex2: add solution 2022-12-15 11:20:11 +01:00
Bruno BELANYI 8c1bf30b3f 2022: d15: ex2: add input 2022-12-15 11:20:11 +01:00
Bruno BELANYI 1d93813e2d 2022: d15: ex1: add solution 2022-12-15 11:20:11 +01:00
2 changed files with 2 additions and 4 deletions

View file

@ -31,8 +31,7 @@ def merge_intervals(intervals: Iterable[Interval]) -> list[Interval]:
res = [intervals[0]]
for candidate in intervals[1:]:
# Range is inclusive in both end, so add 1 to end in case of near miss
if (res[-1].end + 1) >= candidate.start:
if res[-1].end >= candidate.start:
new_end = max(res[-1].end, candidate.end)
res[-1] = Interval(res[-1].start, new_end)
else:

View file

@ -31,8 +31,7 @@ def merge_intervals(intervals: Iterable[Interval]) -> list[Interval]:
res = [intervals[0]]
for candidate in intervals[1:]:
# Range is inclusive in both end, so add 1 to end in case of near miss
if (res[-1].end + 1) >= candidate.start:
if res[-1].end >= candidate.start:
new_end = max(res[-1].end, candidate.end)
res[-1] = Interval(res[-1].start, new_end)
else: