내 답안
class Solution {
public int[] solution(int[] num_list, int n) {
int[] answer = new int[num_list.length];
int index = 0;
for (int i = n; i < num_list.length; i++) {
answer[index++] = num_list[i];
}
for (int i = 0; i < n; i++) {
answer[index++] = num_list[i];
}
return answer;
}
}
Java
복사
다른사람 풀이
class Solution {
public int[] solution(int[] num_list, int n) {
int idx = 0;
int[] answer = new int[num_list.length];
for (int i = n;i < num_list.length;i++)
answer[idx++] = num_list[i];
for (int i = 0;i < n;i++)
answer[idx++] = num_list[i];
return answer;
}
}
Java
복사
class Solution {
public int[] solution(int[] num_list, int n) {
int[] answer = new int[num_list.length];
for (int i=0;i<num_list.length;i++){
if (n == num_list.length) {
n = 0;
}
answer[i] = num_list[n];
n++;
}
return answer;
}
}
Java
복사
class Solution {
public int[] solution(int[] num_list, int n) {
int l = num_list.length;
int[] answer = new int[l];
for (int i = 0; i < l; i++) {
answer[i] = num_list[(i + n) % l];
}
return answer;
}
}
Java
복사