문제
예제
내 풀이
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
int[] arr = {4,5,4};
int[] query = {1,0};
solution(arr, query);
}
public static int[] solution(int[] arr, int[] query) {
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 0; i < arr.length; i++) {
list.add(arr[i]);
}
for (int i = 0; i < query.length; i++) {
ArrayList<Integer> compare = new ArrayList<Integer>();
if(i % 2 == 0){
for(int j = 0; j <= query[i]; j++){
compare.add(list.get(j));
}
}
else {
for (int j = query[i]; j < list.size(); j++) {
compare.add(list.get(j));
}
}
list = compare;
}
int[] answer = new int[list.size()];
for(int i = 0; i < list.size(); i++){
answer[i] = list.get(i);
}
return answer;
}
}