Run #a8295c09
completedScore
100% (4/4)
Runtime
6μs
vs Previous
No change vs parent
Tied for best
Same as parent
Score
100% (4/4)
Runtime
6μs
vs Previous
No change vs parent
Tied for best
Same as parent
import itertools
def solve(input):
if not input:
return []
# Using itertools for an alternative approach to compute differences
result = [input[0]] + [b - a for a, b in itertools.pairwise(input)]
return resultScore Difference
Tied
Runtime Advantage
4μs slower
Code Size
10 vs 9 lines
| # | Your Solution | # | Champion |
|---|---|---|---|
| 1 | import itertools | 1 | def solve(input): |
| 2 | 2 | if not input: | |
| 3 | def solve(input): | 3 | return [] |
| 4 | if not input: | 4 | result = [input[0]] |
| 5 | return [] | 5 | previous = input[0] |
| 6 | 6 | for current in input[1:]: | |
| 7 | # Using itertools for an alternative approach to compute differences | 7 | result.append(current - previous) |
| 8 | result = [input[0]] + [b - a for a, b in itertools.pairwise(input)] | 8 | previous = current |
| 9 | 9 | return result | |
| 10 | return result | 10 |
1import itertools23def solve(input):4 if not input:5 return []6 7 # Using itertools for an alternative approach to compute differences8 result = [input[0]] + [b - a for a, b in itertools.pairwise(input)]9 10 return result1def solve(input):2 if not input:3 return []4 result = [input[0]]5 previous = input[0]6 for current in input[1:]:7 result.append(current - previous)8 previous = current9 return result