https://programmers.co.kr/learn/courses/30/lessons/12981
✅ Solution
- words를 돌면서 usedWords에 있거나 앞사람의 마지막 단어가 아닌 다른 단어로 시작했는지 검사하고
- 만약 그렇다면 몇번째 사람인지, 몇 번째인지 리턴한다.
- 아니라면 usedWords에 word를 넣어준다.
✅ Code
import math
def solution(n, words):
usedWords = []
for idx, word in enumerate(words):
if word in usedWords or (idx >= 1 and words[idx - 1][-1] != word[0]):
return [idx % n + 1, math.ceil((idx + 1) / n)]
usedWords.append(word)
return [0, 0]
'코딩테스트 > 프로그래머스' 카테고리의 다른 글
[프로그래머스] Level 2 - 3xn 타일링 (Python) (0) | 2022.06.25 |
---|---|
[프로그래머스] Level 2 - 구명보트 (Python) (0) | 2022.06.24 |
[프로그래머스] Level 2 - 전력망을 둘로 나누기 (Python) (1) | 2022.06.24 |
[프로그래머스] Level 2 - 피로도 (Python) (0) | 2022.06.23 |
[프로그래머스] Level 2 - 2개 이하로 다른 비트 (Python) (0) | 2022.06.23 |