
내가 작성한 코드
class Solution {
public String solution(String my_string, int[] indices) {
char[] answer = my_string.toCharArray();
// 해당 위치의 문자열 공백으로 치환
for(int i : indices) {
answer[i] = ' ';
}
// 공백 제거 후 반환
return new String(answer).replace(" ", "");
}
}
다른 사람의 코드
class Solution {
public String solution(String my_string, int[] indices) {
String[] str = my_string.split(""); // 문자열 배열화
// 해당 위치 문자열 공백으로 치환
for (int i = 0; i < indices.length; i++)
str[indices[i]] = "";
// "" 기준으로 합치기
return String.join("", str);
}
}
Share article