Java/프로그래머스
[JAVA] 프로그래머스 - 수열과 구간 쿼리 3
쥬크버그
2024. 3. 17. 15:25
https://school.programmers.co.kr/learn/courses/30/lessons/181924
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
query[0][3] -> arr[0]의 값과 arr[3]의 값 교환
query[1][2] -> arr[1]의 값과 arr[2]의 값 교환
query[1][4] -> arr[1]의 값과 arr[4]의 값 교환
정답
class Solution {
public int[] solution(int[] arr, int[][] queries) {
for(int i=0 ;i<queries.length; i++)
{
int idx1 = queries[i][0];
int idx2 = queries[i][1];
int temp = arr[idx1];
arr[idx1] = arr[idx2];
arr[idx2] = temp;
}
return arr;
}
}