코딩테스트/Codility
[Codility] CyclicRotation
꼬몽울
2021. 7. 21. 13:12
https://app.codility.com/programmers/lessons/2-arrays/cyclic_rotation/
CyclicRotation coding task - Learn to Code - Codility
Rotate an array to the right by a given number of steps.
app.codility.com
# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")
def solution(A, K):
answer=[]
if len(A)==0:
answer=A
elif K==0 or K%len(A)==0 or len(A)==K :
answer=A
else:
K=K%len(A)
for i in range(len(A)):
if i+K<len(A):
answer.insert(K+i,A[i])
else:
answer.insert(i+K-len(A),A[i])
return answer