내 답안
class Solution {
public int[] solution(int[] num_list, int n) {
int[] answer = new int[num_list.length - n + 1];
for (int i = n - 1; i < num_list.length; i++) {
answer[i - n + 1] = num_list[i];
}
return answer;
}
}
Java
복사
다른사람 풀이
import java.util.*;
class Solution {
public int[] solution(int[] num_list, int n) {
int[] a= Arrays.copyOfRange(num_list, n-1, num_list.length);
return a;
}
}
Java
복사
class Solution {
public int[] solution(int[] num_list, int n) {
int[] answer = new int[num_list.length - (n-1)];
for(int i=n-1; i<num_list.length; i++) {
answer[i - (n-1)] = num_list[i];
}
return answer;
}
}
Java
복사