728x90
비어있는 배열 들어오는 경우의 수를 생각해줘야한다
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | public int[] solution(int[] A, int K) { // write your code in Java SE 8 if (A.length == 0) return new int[] {}; int[] ans = new int[A.length]; K = K % A.length; for (int i = 0; i < A.length; i++) { // System.out.println(i); ans[(i + K) % A.length] = A[i]; } return ans; } | cs |
'알고리즘 풀이 > Codility' 카테고리의 다른 글
codility - Time Complexity (TapeEquilibrium) (0) | 2019.12.10 |
---|---|
codility - Time Complexity (PermMissingElem) (0) | 2019.12.10 |
codility - Time Complexity (FrogJmp) (0) | 2019.12.10 |
codility - Arrays (OddOccurrencesInArray) (0) | 2019.12.09 |
codility - Iterations (BinaryGap) (0) | 2019.12.09 |