๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Algorithm/ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค

[ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค] ์˜์–ด ๋๋ง์ž‡๊ธฐ - Python

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):
    current_word = [words[0]]
    pre_word = words[0]
    for i in range(1,len(words)): 
        #๋๋ง์ž‡๊ธฐ ๊ทœ์น™์œ„๋ฐ˜
        if pre_word[-1] != words[i][0]:
            return [(i % n)+1, (i//n)+1]
        #์ด๋ฏธ ๋“ฑ์žฅํ•œ ๋‹จ์–ด
        elif words[i] in current_word:
            return [(i % n)+1, (i//n)+1]
        else:
            current_word.append(words[i])
            pre_word = words[i]
            
    return [0,0]