My Java implementation is as follow

```
public class Solution {
public void rotate(int[] nums, int k) {
int n = nums.length;
k = k % n;
if (k == 0)
return;
int index = 0, val = nums[index], counter = 0;
int lastBegin = 0, targetIndex;
while (counter < n) {
targetIndex = (index + k) % n;
int tempVal = nums[targetIndex];
nums[targetIndex] = val;
if (targetIndex == lastBegin) {
index = (targetIndex + 1) % n;
val = nums[index];
lastBegin = index;
}
else {
index = targetIndex;
val = tempVal;
}
counter++;
}
}
}
```

the runtime is about 375ms, it is below the average Java solution performance. I don't quite understand why it is so slow.