DevYoon
[ํ๋ก๊ทธ๋๋จธ์ค] ๋ชจ์๊ณ ์ฌ (Python) ๋ณธ๋ฌธ
link ๐ https://programmers.co.kr/learn/courses/30/lessons/42840
1๏ธโฃ ์ํฌ์๋ณ๋ก ์ฐ๋ ์์๋ฅผ ๋ฆฌ์คํธ์ ๋ด์ ์ฃผ์๊ณ , ๊ฐ๊ฐ for๋ฌธ์ ๋๋ ค ์ ๋ต ๋ฆฌ์คํธ์ ๋ง๋ ๊ฐ์๋ฅผ cnts ๋ฐฐ์ด์ ๋ํด์ฃผ์๋ค.
2๏ธโฃ Max๊ฐ์ max(cnts)๋ก ๋์๊ณ , for๋ฌธ์ ๋๋ ค Max์ ๊ฐ์ผ๋ฉด answer ๋ฆฌ์คํธ์ ์ฝ์ ํด์ฃผ์๋ค!
def solution(answers):
answer = []
cnts = [0]*3
temp1 = [1,2,3,4,5]
temp2 = [2,1,2,3,2,4,2,5]
temp3 = [3,3,1,1,2,2,4,4,5,5]
for idx in range(len(answers)):
if temp1[idx%len(temp1)] == answers[idx]:
cnts[0] += 1
for idx in range(len(answers)):
if temp2[idx%len(temp2)] == answers[idx]:
cnts[1] += 1
for idx in range(len(answers)):
if temp3[idx%len(temp3)] == answers[idx]:
cnts[2] += 1
Max = max(cnts)
for cnt in range(3):
if cnts[cnt] == Max:
answer.append(cnt+1)
return answer