728x90
class Solution {
fun solution(babbling: Array<String>): Int {
var answer: Int = 0
val pos = arrayOf( "aya", "ye", "woo", "ma")
val pos2 = arrayOf( "ayaaya", "yeye", "woowoo", "mama")
for(str in babbling){
var word = str
for(i in pos.indices){
if(word.contains(pos2[i])){
continue
}else if(word.contains(pos[i])){
word=word.replace(pos[i],"|")
}else{
continue
}
}
word=word.replace("|","")
if(word == ""){
answer+=1
}
}
return answer
}
}
분명 예제에서는 되는데 테스트 케이스에서 안되서 질문을 찾아보니 ....
입력값 〉 ["yayae"]
기댓값 〉 0
위에처럼 aya를 제거하면 ye가 되면서 원래는 읽을 수 없는데 제거하면 읽을 수 있게되는 문자들이 생겨서 그런다고 한다.
고민하다가 replace에 | 를 추가해서 단어가 되지 못하게 했다.
728x90
반응형
'개발' 카테고리의 다른 글
TIL: Kotlin컨벤션 (1) | 2023.11.27 |
---|---|
코틀린 1.repeat() 2.count() 3.함수 안될 때 (1) | 2023.11.24 |
프로그래머스: 기사단원의 무기 (1) | 2023.11.22 |
maxOrNull, minOrNull. Kotlin (0) | 2023.11.21 |
20231120 프로그래머스 명예의전당, 2016년 코틀린 (0) | 2023.11.20 |
댓글