내 답안
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;
}
}
Java
복사
다른 사람 풀이법
class Solution {
public int[] solution(int[] arr, int[][] queries) {
int[] answer = {};
for(int i = 0; i < queries.length; i ++){
int one = arr[queries[i][0]];
int two = arr[queries[i][1]];
//System.out.println("One: " + one + ", Two: " + two);
arr[queries[i][0]] = two;
arr[queries[i][1]] = one;
}
return arr;
}
}
Java
복사