class Solution {
public int[] solution(int[] arr, int[][] queries) {
int[] answer = {};
return answer;
}
}
해결법
방법 1
class Solution {
public int[] solution(int[] arr, int[][] queries) {
for (int[] query : queries) {
int i = query[0];
int j = query[1];
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
return arr;
}
}
방법 2
class Solution {
public int[] solution(int[] arr, int[][] queries) {
for (int i = 0; i < queries.length; i ++) {
int one = arr[queries[i][0]];
int two = arr[queries[i][1]];
arr[queries[i][0]] = two;
arr[queries[i][1]] = one;
}
return arr;
}
}
수열과 구간 쿼리 3 Lv. 0