-1
class Solution {
    public int[] solution(int[] A, int K) {
      for (int a = 0; a <= K; a++) {
          for (int j = 0; j < A.length - 1; j++) {
              A[j + 1] = A[j];
              A[0] = A[A.length];
          }
      }
      return A;
    }
}

What is wrong with this code? The next integer should be assigned the value of the previous one and the first one the value of the last one.

Turing85
  • 18,217
  • 7
  • 33
  • 58

1 Answers1

0

It's A[A.length] that causes the error. You forgot to remove 1:

A[0]=A[A.length-1];

And a<=K as well, so change it to a<K.