입출력 예
my_string | indices | result |
"apporoograpemmemprs" | [1, 16, 6, 15, 0, 10, 11, 3] | "programmers" |
입출력 예 설명
입출력 예 #1
- 예제 1번의
my_string
의 인덱스가 잘 보이도록 표를 만들면 다음과 같습니다.
index | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
my_string | a | p | p | o | r | o | o | g | r | a | p | e | m | m | e | m | p | r | s |
`indices`에 있는 인덱스의 글자들을 지우고 이어붙이면 "programmers"가 되므로 이를 return 합니다.
코드
class Solution {
public String solution(String my_string, int[] indices) {
boolean isSame = false;
char[] charList = new char[my_string.length() - indices.length];
int charListIndex = 0;
for(int i = 0; i < my_string.length(); i++) {
isSame = false;
for(int num : indices) {
if(i == num) {
isSame = true;
break;
}
}
if(!isSame) {
charList[charListIndex++] = my_string.charAt(i);
}
}
return new String(charList);
}
}

Share article