Algorithm/프로그래머스

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

potato_pizza 2024. 6. 17. 22:19
728x90

영어 끝말잇기

문제

코드

  • 조건에 만족하면 리스트에 추가(append)하는 방식으로 끝말잇기 진행
  • 조건에 맞지 않는다면 중단하고 return
def solution(n, words):
    lst = [words[0]]
    for i in range(1, len(words)):
        if words[i][0] == words[i-1][-1] and words[i] not in lst:
            lst.append(words[i])
        else:
            return [i%n+1, i//n+1]

    return [0,0]
728x90
반응형