For example, given

A = [3, 8, 9, 7, 6] K = 3

the function should return [9, 7, 6, 3, 8]. Three rotations were made:

[3, 8, 9, 7, 6] -> [6, 3, 8, 9, 7] [6, 3, 8, 9, 7] -> [7, 6, 3, 8, 9] [7, 6, 3, 8, 9] -> [9, 7, 6, 3, 8]

For another example, given

A = [0, 0, 0] K = 1

the function should return [0, 0, 0]

Given

A = [1, 2, 3, 4] K = 4

the function should return [1, 2, 3, 4]


설명:

A 의 배열을 K 만큼 우측 으로 이동했을시 나오는 A를 반환하면 된다.




class Solution { public int[] solution(int[] A, int K) { // write your code in Java SE 8 int[] rotaionA = new int[A.length]; for(int i =0;i< A.length;i++){ rotaionA[ (i+K) % A.length ] = A[i]; } return rotaionA; } }




'프로그래밍 > 알고리즘' 카테고리의 다른 글

시간 복잡도  (0) 2018.04.21
[Codility] CountSemiprimes  (0) 2018.04.21
[Codility] Stone wall  (0) 2018.04.15
[Codility] Binary Gap 알고리즘  (0) 2018.04.14
알고리즘 공부 사이트  (0) 2017.01.27
블로그 이미지

낭만가을

,