Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 |
Tags
- 운영체제
- dict
- 딕셔너리
- 브루트포스
- 재귀
- python
- 백준
- level0
- 코딩테스트
- 스택
- 다익스트라
- 다이나믹 프로그래밍
- dfs
- 구현
- BFS
- 프로그래머스
- 가상메모리
- level2
- DP
- N과M
- level1
- 가상메모리 관리
- level3
- 그리디
- programmers
- 파이썬
- MYSQL
- BOJ
- 힙
- 수학
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level2 [영어 끝말잇기] 파이썬 본문
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
#프로그래머스 영어 끝말잇기
def solution(n, words):
lst=[]
cnt=-1
previous=words[0][0]
for i in range(len(words)):
if previous==words[i][0]:
if words[i] not in lst:
lst.append(words[i])
previous=words[i][-1]
else:
cnt=(i)
break
else:
cnt=(i)
break
if cnt==-1:
answer=[0,0]
else:
answer=[(cnt%n)+1,(cnt//n)+1]
return answer
previous에 이전 단어의 마지막 글자를 저장한다. previous와 다음 단어의 첫 글자가 일치하고, lst에 단어가 존재하면 lst에 단어를 추가하고, previous를 갱신한다.
그렇지 않다면, 반복문을 탈출하고, 순서와 차례를 계산한다.
'코테 > 프로그래머스' 카테고리의 다른 글
프로그래머스 level2 [2개 이하로 다른 비트] 파이썬 (0) | 2021.12.08 |
---|---|
프로그래머스 level2 [예상 대진표] 파이썬 (0) | 2021.12.07 |
프로그래머스 level2 [모음사전] 파이썬 (0) | 2021.12.07 |
프로그래머스 level2 [주식가격] 파이썬 (0) | 2021.12.07 |
프로그래머스 level2 [괄호 회전하기] 파이썬 (0) | 2021.12.06 |