programmers : 신규 아이디 추천

이진솔·2022년 2월 9일
post-thumbnail
class Solution {
    public String solution(String new_id) {
        // 1단계
        String lower = new_id.toLowerCase();
        // 2단계
        char[] lowerchar = lower.toCharArray();
        StringBuilder step2 = new StringBuilder();
        for (char c : lowerchar) {
            if ((c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || (c == '-' || c == '_' || c == '.')) {
                step2.append(c);
            }
        }
        // 3단계
        String step3 = step2.toString().replace("..", ".");
        while (step3.contains("..")) {
            step3 = step2.replace("..", ".");
        }
        // 4단계

        return answer;
    }
}
profile
"Hello Jinsol World"💛

0개의 댓글