PS/프로그래머스
[프로그래머스 LV 2] 영어 끝말잇기 파이썬/python
BLUE_ERASER
2021. 6. 5. 03:40
728x90
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
그냥 주어진 방법대로 구현함...
진짜 주먹구구식으로 구현만 한거라 크게 볼건 없을듯...?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
def solution(n, words):
answer = [0, 0]
word_map = {} # 사용했던적 있는 단어인지 판단용
temp = words[0][0]
round_num = 1 # 몇 번쨰 라운드인지
while 1:
for i in range(n):
if words[0] not in word_map:
if temp == words[0][0]:
temp = words[0][-1]
word_map[words.pop(0)] = 1
else:
result = [i + 1, round_num]
return result
else:
result = [i + 1, round_num]
return result
round_num += 1
if len(words) == 0:
break
return answer
|
cs |
728x90