본문 바로가기
알고리즘/프로그래머스 level 1,2

[파이썬🐍] 프로그래머스 : 영어 끝말잇기

by 코딩개미뚠뚠 2021. 5. 14.
반응형
import math
def solution(n, words):
    for i in range(0,len(words)):
        if words[i-1][-1] != words[i][0] and i >= 1: #앞 단어의 마지막 알파벳으로 시작하는지 확인
            return i%n+1, math.ceil((i+1)/n)         #몇 번째 사람, 몇 번째 차례
        if words[i] in words[0:i]:                   #전에 나온 단어인지 확인
            return i%n+1, math.ceil((i+1)/n)         #몇 번째 사람, 몇 번째 차례
            
    return 0,0

 

반응형

댓글