ye0nn
영차영차
ye0nn
전체 방문자
오늘
어제
  • 분류 전체보기 (61)
    • CS (0)
      • 운영체제 (0)
      • 네트워크 (0)
      • 알고리즘 & 자료구조 (0)
    • 코딩테스트 (48)
      • 프로그래머스 (40)
      • 백준 (8)
    • 프로그래밍 (11)
      • 프론트엔드 (3)
      • 자바스크립트 (0)
      • 스위프트 (7)
      • 파이썬 (1)
    • 취준기록 (1)

인기 글

블로그 메뉴

  • 홈
  • 태그
  • 방명록

티스토리

hELLO · Designed By 정상우.
ye0nn

영차영차

[프로그래머스] Level 2 - 영어 끝말잇기 (Python)
코딩테스트/프로그래머스

[프로그래머스] Level 2 - 영어 끝말잇기 (Python)

2022. 6. 24. 17:52

 

 

 

 

 

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

 

 

 

 

 

✅ Solution

  • words를 돌면서 usedWords에 있거나 앞사람의 마지막 단어가 아닌 다른 단어로 시작했는지 검사하고 
    • 만약 그렇다면 몇번째 사람인지, 몇 번째인지 리턴한다.
    • 아니라면 usedWords에 word를 넣어준다.

 

 

 

 

✅ Code

import math

def solution(n, words):
    usedWords = []

    for idx, word in enumerate(words):
        if word in usedWords or (idx >= 1 and words[idx - 1][-1] != word[0]):
            return [idx % n + 1, math.ceil((idx + 1) / n)]

        usedWords.append(word)

    return [0, 0]

 

 

 

 

 

 

저작자표시 (새창열림)

'코딩테스트 > 프로그래머스' 카테고리의 다른 글

[프로그래머스] Level 2 - 3xn 타일링 (Python)  (0) 2022.06.25
[프로그래머스] Level 2 - 구명보트 (Python)  (0) 2022.06.24
[프로그래머스] Level 2 - 전력망을 둘로 나누기 (Python)  (1) 2022.06.24
[프로그래머스] Level 2 - 피로도 (Python)  (0) 2022.06.23
[프로그래머스] Level 2 - 2개 이하로 다른 비트 (Python)  (0) 2022.06.23
    '코딩테스트/프로그래머스' 카테고리의 다른 글
    • [프로그래머스] Level 2 - 3xn 타일링 (Python)
    • [프로그래머스] Level 2 - 구명보트 (Python)
    • [프로그래머스] Level 2 - 전력망을 둘로 나누기 (Python)
    • [프로그래머스] Level 2 - 피로도 (Python)
    ye0nn
    ye0nn
    프론트엔드 개발자의 개발기록

    티스토리툴바