문제링크: 옹알이
✍🏻 Information
| content | |
|---|---|
| 언어 | python |
| 난이도 | ⭐️⭐️+0.5 |
| 풀이시간 | 20분 |
| 제출횟수 | 5 |
| 인터넷검색유무 | no |
🍒 My Code
def solution(babbling):
speak = ["aya","ye","woo","ma"]
answer = 0
for i in babbling:
point = 0 #현재 위치(옮겨가며 speak 중에 있는지 찾음)
before = '' #직전에 speak 중 찾은 문자열
while point<len(i):
nothing = True
for j in speak:
if i.find(j,point)==point and before!=j:
point+=len(j)
nothing = False
before = j
break
if nothing==True: #못찾으면 바로 끝내기
break
if point==len(i):
answer+=1
return answer
💡 What I learned
무한루프의 굴레에 빠졌었는데 i.find(j)로 해놨어서, nothing 초기화를 while문 밖에 해둬서였다.
좋다고 생각한 풀이
def solution(babbling):
answer = 0
for i in babbling:
for j in ['aya','ye','woo','ma']:
if j*2 not in i:
i=i.replace(j,' ')
if len(i.strip())==0:
answer +=1
return answer
ㄴ 근데 replace에서 빈칸이 아니라 ''로 하면 안된다. 왤까