1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| class Solution { public int[] decrypt(int[] code, int k) { int[] ans = new int[code.length];
for (int i = 0; i < ans.length; i++) { if (k < 0) { for (int j = k; j < 0; j++) { ans[i] += code[(i + code.length + j) % code.length]; } } else if (k > 0) { for (int j = 1; j <= k; j++) { ans[i] += code[(i + j) % code.length]; } } }
return ans; } }
|