Today
Total
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
관리 메뉴

기억은 짧고 기록은 길다

[프로그래머스/Programmers] 영어 끝말잇기 - Python 본문

CodingTest/programmers

[프로그래머스/Programmers] 영어 끝말잇기 - Python

ukunV 2021. 10. 6. 14:54

Link

 

코딩테스트 연습 - 영어 끝말잇기

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

 

Solution

def solution(n, words):
    for i in range(1, len(words)):
        if words[i] in words[:i] or words[i - 1][-1] != words[i][0]:
            return [i % n + 1, i // n + 1]
    else:
        return [0, 0]
🔑 key point: return [i % n + 1, i // n + 1]
Comments