๐ก string ์ ๋ฐฐ์ด๋ก ๋ณ๊ฒฝํด์ ์ฝ๊ฒ ํ ์ ์๋ค!!
๐ฌ ๋ฃจํ ๋ณ์ index : indices ๋ฐฐ์ด์ ์๋ ๊ฐ๊ฐ์ ์ธ๋ฑ์ค์ ๋ํด ๋ฐ๋ณต
๐ฌ String.join() : ์ฒซ ๋ฒ์งธ ์ธ์๋ ๊ฐ ์์๋ฅผ ๊ตฌ๋ถํ ๋ฌธ์์ด์ด๋ฉฐ, ๋ ๋ฒ์งธ ์ธ์๋ ์ฐ๊ฒฐํ ๋ฌธ์์ด ๋ฐฐ์ด
class Solution {
public String solution(String my_string, int[] indices) {
String[] str = my_string.split("");
for ( int index : indices ) { //indices ๋ฐฐ์ด์ index ๋ฐ๋ณต
str[ index ] = ""; // ํด๋น ์ธ๋ฑ์ค ๊ฐ์ "" ์ง์ฐ๊ธฐ
}
return String.join( "", str ); //๋น ๋ฌธ์์ด๋ก ์ฐ๊ฒฐํ์ฌ ํ๋์ ๋ฌธ์์ด๋ก ๋ฐํ
}
}
์คํจํ ์ฝ๋
class Solution {
public String solution(String my_string, int[] indices) {
String answer = "";
int num = 0;
for (int i = 0 ; i< my_string.length(); i++){
if ( i != indices[num]) {
answer += my_string.charAt(i);
}
}
return answer;
}
}