[ํ๋ก๊ทธ๋๋จธ์ค] 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]
'๐ป Coding Problems Solving > Array | String | Loop' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ํํ (0) | 2022.04.12 |
---|---|
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 H-Index (0) | 2022.04.11 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๊ฐ์ฅ ํฐ ์ (0) | 2022.04.07 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 ๊ธฐ๋ฅ๊ฐ๋ฐ (0) | 2022.04.07 |
[ํ๋ก๊ทธ๋๋จธ์ค] LV.2 124 ๋๋ผ์ ์ซ์ (0) | 2022.04.07 |
์ต๊ทผ๋๊ธ