반응형
문제는 이러하다..
그래서 몇가지를 시도를 해보았다.
str.indexOf() 를 썼더니, 인식하지 못하길래 패스..
구글링 하다가 보니, str.replace("a", "b") 라는 함수를 발견!
그 전에 한번도 써보지 않은 것인데, a를 b로 바꾼다는 의미이다.
아무튼, 단순 무식한 방법으로 쭉 나열했다.
public class Troll {
public static String disemvowel(String str) {
// Code away...
String str2;
str2 = str.replace("e", "");
str2 = str2.replace("i", "");
str2 = str2.replace("o", "");
str2 = str2.replace("u", "");
str2 = str2.replace("a", "");
str2 = str2.replace("O", "");
str2 = str2.replace("I", "");
str2 = str2.replace("U", "");
str2 = str2.replace("E", "");
str2 = str2.replace("A", "");
return str2;
}
}
결과는.. 성공!
그리고 문제를 다 풀고 나면,
다른 사람들이 푼 답들을 보여주는데....
이렇게 하면 되는거구나..................... 하하하
반응형
'SOFTWARE > ALGORITHM' 카테고리의 다른 글
[codewars] Is a number prime? - 소수인 숫자 찾기 (0) | 2020.02.17 |
---|---|
[codewars] Sum of odd numbers (0) | 2020.02.16 |
[codewars] A square of squares - 제곱수 구하기! (0) | 2020.02.15 |
[codewars] Isograms - 문자열 비교하기 (0) | 2020.02.14 |
[코딩테스트 연습]SUM, MAX, MIN - 최댓값 구하기 (0) | 2020.01.30 |
댓글