๐ป Coding Problems Solving/Array | String | Loop
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์์ด ๋๋ง์๊ธฐ
Kim_dev
2022. 4. 8. 16:43
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ์์ด ๋๋ง์๊ธฐ
1. ๋ฌธ์ : Link
๋๋ง์๊ธฐ ์งํ ์ค ๋ง์ฝ ํ๋ฝ์๊ฐ ๋์จ๋ค๋ฉด ๋ช๋ฒ์งธ ์ฌ๋์ด ๋ช๋ฒ์งธ ์ฐจ๋ก์ ์ค์๋ฅผ ํ๋์ง return
2. ํ์ด
๋๋ง์ ์๋์ง ์ฌ๋ถ์ ์ค๋ณต ์ฌ๋ถ๋ฅผ ๋ฐ๋ณต๋ฌธ์ผ๋ก ํ์ธ
cnt์ turn์ ํตํด ์ฐจ๋ก๋ฅผ ํ์ธํ๊ณ
tmp๋ก ์ค๋ณต์ ํ์ธํ ์ ์๋ค.
3. ์ฝ๋
def solution(n, words):
answer = []
temp = []
num = [i for i in range(1,n+1)]
cnt, turn = 0, 0
for word in words:
cnt += 1
if cnt % n == 1:
turn += 1
if len(temp) == 0:
temp.append(word)
else:
if word[0] != temp[-1][-1] or word in temp:
answer = [num[cnt%n-1], turn]
return answer
else:
temp.append(word)
return [0,0]