코드
def solution(n, words):
answer = []
res=[words[0]]
p=2
for i in range(1,len(words)):
if words[i] in res:
cnt=(i+1)//n if (i+1)%n==0 else ((i+1)//n)+1
answer=[p,cnt]
break
else:
res.append(words[i][0])
if words[i-1][-1]==words[i][0]:
if p<n:
p+=1
else:
p=1
else:
cnt=(i+1)//n if (i+1)%n==0 else ((i+1)//n)+1
answer=[p,cnt]
break
else:
answer=[0,0]
return answer
다른 사람의 풀이
def solution(n,words):
for i in range(1,len(words)):
if words[i-1][-1]!=words[i][0] or words[i] in words[:i]:
return [(i%n)+1, 1+(i//n)]
else:
return [0,0]