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 | 31 |
Tags
- 안드로이드
- aws
- 다트
- 소프티어
- kotlin
- 스위프트
- 코틀린
- Flutter
- 아마존 웹 서비스
- GDSC
- 백준
- 파이썬
- softeer
- 머신러닝
- MVVM
- DART
- baekjoon
- VSCode
- 프로그래머스
- SWIFT
- 코테
- 알고리즘
- 개발
- 플러터
- Android
- java
- 현대sw
- 자바
- programers
- Python
Archives
- Today
- Total
조준장 개발자 생존기
[programers] 프로그래머스(파이썬) : 영어 끝말잇기 본문
문제
코딩테스트 연습 - 영어 끝말잇기
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
알고리즘
- 반복문을 통해서 단어를 확인한다.
- 규칙에 어긋나면 반복을 멈춘다.
- 확인한 단어와 입력받은 단어가 같으면 틀린 사람이 없는 것이다.
- 틀린 사람의 번호와 차례는 게임을 한 사람 수의 나머지와 나누기를 통해 구한다.
코드
import math
def solution(n, words):
answer = []
temp = []
# 반복문을 통해 단어 확인
for i in words:
# 규칙에 어긋나면 멈춘다.
if (len(temp) > 0 and temp[-1][-1] != i[0]) or i in temp:
break
temp.append(i)
if temp == words:
answer = [0,0]
else:
c = (len(temp) % n) + 1 # 번호
d = math.ceil((len(temp) + 1) / n) # 차례
answer = [c, d]
return answer
github
GitHub - junjange/CodingTest: 내가 푼 코딩 테스트 문제와 해결법
내가 푼 코딩 테스트 문제와 해결법. Contribute to junjange/CodingTest development by creating an account on GitHub.
github.com
'CodingTest > Programers' 카테고리의 다른 글
[programers] 프로그래머스(파이썬) : 스킬트리 (0) | 2022.04.26 |
---|---|
[programers] 프로그래머스(파이썬) : 점프와 순간 이동 (0) | 2022.04.25 |
[programers] 프로그래머스(파이썬) : 배달 (0) | 2022.04.24 |
[programers] 프로그래머스(파이썬) : 신규 아이디 추천 (0) | 2022.04.24 |
[programers] 프로그래머스(파이썬) : 로또의 최고 순위와 최저 순위 (0) | 2022.04.24 |