본문 바로가기
개발/알고리즘

[codility] CyclicRotation

by ny0011 2021. 2. 16.
반응형

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

배열 돌리기다

def solution(A, K):
    # write your code in Python 3.6
    n = len(A)
    if n == 0:
        return A
    k = K % n
    if k == 0:
        return A
    
    return A[n-k:] + A[:n-k]

'개발 > 알고리즘' 카테고리의 다른 글

[codility] FrogJmp  (0) 2021.02.16
[codility] OddOccurrencesInArray  (0) 2021.02.16
[codility] BinaryGap  (0) 2021.02.16
[프로그래머스] 이진 변환 반복하기  (0) 2021.02.15
[프로그래머스] 행렬의 곱셈  (0) 2021.02.15

댓글