File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ def solution (n , words ):
2+ done = [words [0 ]] # 사용한 단어 저장
3+ flag = 0
4+ for i in range (1 , len (words )):
5+ # 중복 단어 체크
6+ if words [i ] in done :
7+ person = (i % n ) + 1
8+ turn = ( i // n ) + 1
9+ return [person , turn ]
10+ # 끝말잇기 이어지는지 체크
11+ if done [i - 1 ][- 1 ] != words [i ][0 ]:
12+ person = (i % n ) + 1
13+ turn = ( i // n ) + 1
14+ return [person , turn ]
15+
16+ # 조건 통과하면 단어 추가
17+ done .append (words [i ])
18+
19+ # 탈락자가 없으면 [0,0] 반환
20+ return [0 ,0 ]
21+
22+
23+ '''
24+ GPT
25+ '''
26+ '''
27+ def solution(n, words):
28+ used_words = set() # 이미 사용된 단어를 저장하는 집합
29+ used_words.add(words[0]) # 첫 번째 단어는 미리 저장
30+ for i in range(1, len(words)):
31+ # 중복 단어 사용 여부 체크
32+ if words[i] in used_words:
33+ person = (i % n) + 1
34+ turn = (i // n) + 1
35+ return [person, turn]
36+ # 끝말잇기 규칙 체크 (이전 단어의 마지막 글자와 현재 단어의 첫 글자 비교)
37+ if words[i][0] != words[i-1][-1]:
38+ person = (i % n) + 1
39+ turn = (i // n) + 1
40+ return [person, turn]
41+ # 조건을 모두 통과하면 단어를 집합에 추가
42+ used_words.add(words[i])
43+ # 탈락자가 없으면 [0, 0] 반환
44+ return [0, 0]
45+
46+ '''
You can’t perform that action at this time.
0 commit comments