내 답안
class Solution {
public String solution(String my_string, String overwrite_string, int s) {
String answer = my_string.substring(0,s)+overwrite_string;
if(my_string.length() > answer.length() ){
answer += my_string.substring(answer.length());
}
return answer;
}
}
Java
복사
다른 사람 풀이법
class Solution {
public String solution(String my_string, String overwrite_string, int s) {
String before = my_string.substring(0, s);
String after = my_string.substring(s + overwrite_string.length());
return before + overwrite_string + after;
}
}
Java
복사
class Solution {
public String solution(String my_string, String overwrite_string, int s) {
char[] my_chars = my_string.toCharArray();
char[] overwrite_chars = overwrite_string.toCharArray();
for (int i=0; i<overwrite_chars.length; i++) {
my_chars[s + i] = overwrite_chars[i];
}
return String.valueOf(my_chars);
}
}
Java
복사