내 답안
class Solution {
public String solution(String my_string, int s, int e) {
String answer = my_string.substring(s,e+1);
StringBuffer sb = new StringBuffer(answer);
String reverseSt = sb.reverse().toString();
my_string = my_string.replaceAll(answer, reverseSt);
return my_string;
}
}
Java
복사
다른사람 풀이
class Solution {
public String solution(String my_string, int s, int e) {
StringBuilder answer = new StringBuilder(my_string.substring(s, e + 1));
answer.reverse();
return my_string.substring(0, s) + answer + my_string.substring(e + 1);
}
}
Java
복사
class Solution {
public String solution(String my_string, int s, int e) {
char[] arr = my_string.toCharArray();
while (s < e) {
char temp = arr[s];
arr[s++] = arr[e];
arr[e--] = temp;
}
return new String(arr);
}
}
Java
복사