알고리즘-python/Programmers 문제
[프로그래머스/2단계/파이썬(Python3)] 영어 끝말잇기
빅데이터1020
2021. 6. 25. 23:14
SMALL
문제 출처
코딩테스트 연습 - 영어 끝말잇기
3 ["tank", "kick", "know", "wheel", "land", "dream", "mother", "robot", "tank"] [3,3] 5 ["hello", "observe", "effect", "take", "either", "recognize", "encourage", "ensure", "establish", "hang", "gather", "refer", "reference", "estimate", "executive"] [0,0]
programmers.co.kr
풀이 코드
def solution(n, words):
if len(words[0])==1:
answer=[0,1]
else:
compare=[words[0]]
for i in range(1, len(words)):
if len(words[i])==1:
break
elif words[i-1][-1]==words[i][0] and words[i] not in compare:
compare.append(words[i])
else:
break
if len(compare)==len(words):
answer = [0, 0]
if len(compare)!=len(words):
idx_p=(len(compare)%n)+1
idx_s=len(compare)//n+1
answer=[idx_p, idx_s]
return answer
LIST