class Solution(object):
def constructArray(self, n, k):
"""
:type n: int
:type k: int
:rtype: List[int]
"""
# 定义原始的列表,此时差值只有1种,均为1
res = list(range(1,n+1))
# 每次翻转1-n的列表,此时就会增加一种差值,第一个和最后一个
# 翻转的元素是-1到i
for i in range(1,k):
res[i:] = res[:i-1:-1]
return res
Un Leetcode por día: 667. Hermoso arreglo II
Supongo que te gusta
Origin blog.csdn.net/weixin_41041275/article/details/112694234
Recomendado
Clasificación