if 조건문을 너무 많이 넣어서 수행시간이 늘어진거 같은데...
실제로 다른 사람들이 0.1초에 풀이될때 거의 8초 걸린다...
replace에 대해 알아보자
class Solution {
public int solution(String[] babbling) {
int answer = 0;
for(int i = 0; i < babbling.length; i++){
String currentStr = babbling[i];
System.out.println("\n현재 문자열 : " + currentStr);
int start = 0;
int currentStrLen = currentStr.length();
while(true)
{
if(start == currentStrLen){
System.out.println("통과한 문자열 : " + currentStr + "\n");
answer++;
break;
}
if((start + 3 <= currentStrLen) && currentStr.substring(start, start + 3).equals("aya")){
if(start - 3 >= 0 && currentStr.substring(start - 3, start).equals("aya")){
break;
}
else{
start += 3;
}
}
else if((start + 2 <= currentStrLen) && currentStr.substring(start, start + 2).equals("ye"))
{
if(start - 2 >= 0 && currentStr.substring(start - 2, start).equals("ye")){
break;
}
else{
start += 2;
}
}
else if((start + 3 <= currentStrLen) && currentStr.substring(start, start + 3).equals("woo"))
{
if(start - 3 >= 0 && currentStr.substring(start - 3, start).equals("woo")){
break;
}
else{
start += 3;
}
}
else if((start + 2 <= currentStrLen) && currentStr.substring(start, start + 2).equals("ma"))
{
if(start - 2 >= 0 && currentStr.substring(start - 2, start).equals("ma")){
break;
}
else{
start += 2;
}
}
else{
break;
}
}
}
return answer;
}
}