내 답안
class Solution {
public String solution(String my_string, int[][] queries) {
char[] arr = my_string.toCharArray();
for (int[] query : queries) {
int start = query[0];
int end = query[1];
while (start < end) {
char temp = arr[start];
arr[start] = arr[end];
arr[end] = temp;
start++;
end--;
}
}
return new String(arr);
}
}
Java
복사
다른 사람 풀이법
class Solution {
char[] arr;
public String solution(String my_string, int[][] queries) {
arr = my_string.toCharArray();
for (int[] query : queries) {
reverse(query[0], query[1]);
}
return new String(arr);
}
private void reverse(int s, int e) {
while (s < e) {
char temp = arr[s];
arr[s++] = arr[e];
arr[e--] = temp;
}
}
}
Java
복사