class Solution {
public String solution(String new_id) {
String answer = new_id.toLowerCase(); // 1๋จ๊ณ
answer = answer.replaceAll("[^-_.a-z0-9]", ""); // 2๋จ๊ณ
answer = answer.replaceAll("[.]{2,}", "."); // 3๋จ๊ณ
answer = answer.replaceAll("^[.]|[.]$", ""); // 4๋จ๊ณ
if (answer.equals("")) { // 5๋จ๊ณ
answer += "a";
}
if (answer.length() >= 16) { // 6๋จ๊ณ
answer = answer.substring(0, 15);
answer = answer.replaceAll("[.]$","");
}
if (answer.length() <= 2) { // 7๋จ๊ณ
while (answer.length() < 3) {
answer += answer.charAt(answer.length()-1);
}
}
return answer;
}
}
๋ฌธ์ ๋งํฌ : https://school.programmers.co.kr/learn/courses/30/lessons/72410
'๐ป Coding Problems Solving > Hack' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java] ํธ๋ํ์ดํธ ๋ํ๋ก ์์๋ณด๋ string, char, int (0) | 2022.11.16 |
---|---|
[JAVA] ๋คํธ๊ฒ์์ ํตํด ์์๋ณด๋ char ๋ฌธ์/์ซ์ ํ์ธ (0) | 2022.10.14 |
[JAVA] 2์ง์, 8์ง์, 16์ง์ + ์ฑ์๋ฃ๊ธฐ! (0) | 2022.10.13 |
[JAVA] ์์ ์ํธ (0) | 2022.10.13 |
[JAVA] ์ฝ๋ฉํ ์คํธ ์ ์ฉํ ์ฝ๋ ๋ชจ์ (0) | 2022.10.07 |
์ต๊ทผ๋๊ธ