1. 개요
2. 풀이
def solution(babbling):
verbs = set(["aya", "ye", "woo", "ma"])
answer = 0
for b in babbling:
stack, lastWord, flag = [], "", True
for c in b:
stack.append(c)
curWord = "".join(stack)
if curWord == lastWord:
flag = False
break
if curWord in verbs:
lastWord = curWord
stack.clear()
answer += (flag and not stack)
return answer
3. 정규식 풀이
def solution(babbling):
answer = 0
REGEXA = "aya|ye|woo|ma"
REGEXB = "ayaaya|yeye|woowoo|mama"
for b in babbling:
# 다른발음이 있는지 체크한다.
if sum(len(c) for c in re.findall(REGEXA, b)) != len(b):
continue
# 연속된 발음이 있는지 체크한다.
if re.findall(REGEXB, b):
continue
answer += 1
return answer
Leave a comment