Run #3d91a34a
completedScore
100% (4/4)
Runtime
10μs
vs Previous
No change vs parent
Tied for best
Same as parent
Score
100% (4/4)
Runtime
10μs
vs Previous
No change vs parent
Tied for best
Same as parent
from array import array
def solve(input):
if len(input) <= 1:
return input[:]
diffs = array('i')
diffs.append(input[0])
for i in range(1, len(input)):
diffs.append(input[i] - input[i - 1])
return list(diffs)Score Difference
Tied
Runtime Advantage
8μs slower
Code Size
13 vs 9 lines
| # | Your Solution | # | Champion |
|---|---|---|---|
| 1 | from array import array | 1 | def solve(input): |
| 2 | 2 | if not input: | |
| 3 | def solve(input): | 3 | return [] |
| 4 | if len(input) <= 1: | 4 | result = [input[0]] |
| 5 | return input[:] | 5 | previous = input[0] |
| 6 | 6 | for current in input[1:]: | |
| 7 | diffs = array('i') | 7 | result.append(current - previous) |
| 8 | diffs.append(input[0]) | 8 | previous = current |
| 9 | 9 | return result | |
| 10 | for i in range(1, len(input)): | 10 | |
| 11 | diffs.append(input[i] - input[i - 1]) | 11 | |
| 12 | 12 | ||
| 13 | return list(diffs) | 13 |
1from array import array23def solve(input):4 if len(input) <= 1:5 return input[:]6 7 diffs = array('i') 8 diffs.append(input[0])9 10 for i in range(1, len(input)):11 diffs.append(input[i] - input[i - 1])12 13 return list(diffs)1def 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