알고리즘 풀이/Codility
codility - Arrays (CyclicRotation)
배게
2019. 12. 9. 23:43
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 |