https://school.programmers.co.kr/learn/courses/30/lessons/133499
유명한 옹알이 문제이다. 문자열을 치환할 때 문자열을 빈문자열로 만들어 버리면 다른 단어들끼리 합쳐지면서 새로운 발음 가능한 단어가 탄생한다는 것을 간과했어서 진짜 존나 오래 걸렸다 ㅜㅠ
def solution(babbling):
answer = 0
cap = ["aya", "ye", "woo", "ma"]
d_cap = ['ayaaya','yeye','woowoo','mama']
b = []
b2 = []
for i in babbling:
if i in cap:
answer += 1
else:
b.append(i)
for i in b:
count = 0
for e in d_cap:
if e in i:
count +=1
if count == 0:
b2.append(i)
for i in range(len(b2)):
j = 0
while j < 16:
for e in cap:
if e in b2[i]:
b2[i] = b2[i].replace(e,' ')
j+=1
for i in b2:
i = i.strip()
if len(i) == 0:
answer +=1
return answer
i = i.strip()
빈문자열이라면 공백으로 만들어서 길이를 비교했다.