Beautiful Arrangement II LeetCode solution in Python

1
class Solution:
2
def constructArray(self, n: int, k: int) -> List[int]:
3
# n = 8, k = 5
4
# 1 2 3 8 4 7 5 6
5
# 1 1 5 4 3 2 1
6
res = list(range(1, n - k + 1))
7
sign, val = 1, k
8
for i in range(k):
9
res.append(res[-1] + sign * val)
10
sign *= -1
11
val -= 1
12
return res

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0