내 답안
import java.util.*;
class Solution {
public String solution(String my_string, int m, int c) {
List<String> result = new ArrayList<>();
for (int i = 0; i < my_string.length(); i += m) {
String str = my_string.substring(i, i + m);
result.add(str);
}
String answer = "";
for (String res : result) {
answer += res.substring(c-1, c);
}
return answer;
}
}
Java
복사
다른사람 풀이
class Solution {
public String solution(String my_string, int m, int c) {
String answer = "";
for (int i = c - 1; i < my_string.length(); i += m) {
answer += my_string.charAt(i);
}
return answer;
}
}
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
복사