프로그래머스(Java)/Lv0

[프로그래머스 : 코딩테스트 입문]Lv0. 특정 문자 제거하기(Java)

지미지민 2024. 3. 23. 23:15

 

 

 

💜 코드


class Solution {
    public String solution(String my_string, String letter) {
        String result = "";
        char tg = letter.charAt(0);
        for(int i=0; i<my_string.length(); i++){
            if(my_string.charAt(i) != tg ){
                result += my_string.charAt(i);
            }
        }
        return result;
    }
}

 

 

 

💜 실행 결과


 

 

 

💜 다른 사람의 풀이


class Solution {
    public String solution(String my_string, String letter) {
        String answer = "";

        answer = my_string.replace(letter, "");

        return answer;
    }
}