반응형
https://programmers.co.kr/learn/courses/30/lessons/12981
코딩테스트 연습 - 영어 끝말잇기 | 프로그래머스
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


주어진 조건대로 구현하면 되는 문제.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(n, words): | |
# 처음으로 말한 단어 저장 | |
dataset = set([words[0]]) | |
# 이전 단어 기억 | |
prev_words = words[0] | |
for i in range(1,len(words)): | |
# 이전 단어의 마지막 글자와 제시단어의 첫글자가 다르거나, 이미 있는 단어일 경우 | |
if (prev_words[-1] != words[i][0]) or words[i] in dataset: | |
# 사람, 차례 | |
return [(i % n)+1, (i//n)+1] | |
# 등장한 단어 저장 | |
dataset.add(words[i]) | |
# 제시단어 기억 | |
prev_words = words[i] | |
return [0,0] |
반응형
'프로그래밍 > 코딩테스트 문제풀이' 카테고리의 다른 글
[Python] 백준 13460. 구슬 탈출 2 (0) | 2020.02.14 |
---|---|
[Python] 백준 2110. 공유기 설치 (0) | 2020.02.13 |
[Python] 백준 17281. ⚾ (2) | 2020.02.11 |
[Python] 백준 1021. 회전하는 큐 (0) | 2020.02.10 |
[Python] 프로그래머스. 예산 (Level 3) (0) | 2020.02.08 |