248. CyclicRotation

아현·2021년 8월 13일
0

Algorithm

목록 보기
260/400



1. Python



from collections import deque

def solution(A, K):
    array = deque(A)
    array.rotate(K)
    return list(array)


  



데크 미사용


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



2. JavaScript



function solution(A, K) {
    const rotationNum = (K > A.length) ? (K % A.length) : K;
    return rotationNum === 0 ? A : [].concat(A.slice(-rotationNum), A.slice(0, A.length - rotationNum));
}


profile
For the sake of someone who studies computer science

0개의 댓글