def solution(answers):
length = len(answers)
first_person_answer = [1,2,3,4,5] * 5001
second_person_answer = [2,1,2,3,2,4,2,5] * 1251
third_person_answer = [3,3,1,1,2,2,4,4,5,5] * 1001
scores = [0, 0, 0]
for i in range(0, length):
scores[0] += 1 if first_person_answer[i] == answers[i] else 0
scores[1] += 1 if second_person_answer[i] == answers[i] else 0
scores[2] += 1 if third_person_answer[i] == answers[i] else 0
great_score = max(scores)
great_scorer = [i+1 for i in range(0,3) if scores[i] == great_score]
return great_scorer
다른 사람들 코드 보니까 인덱스로 나머지 연산해서 풀었더라..
근데 생각해보니 인덱스로 나머지 연산하면 for문 돌릴 때마다 세 번 연산 해야 하는데 그냥 배열 길이 늘리는 것도 나쁘지 않을 지도..?
'조열심 카테고리 > 알고리즘' 카테고리의 다른 글
| [프로그래머스] 피로도 (0) | 2022.09.27 |
|---|---|
| [프로그래머스] 주식가격 (0) | 2022.09.26 |
| [프로그래머스] 멀리 뛰기 (0) | 2022.09.26 |
| [프로그래머스] 예상 대진표 (10) | 2022.09.25 |
| [프로그래머스] 영어 끝말잇기 (0) | 2022.09.25 |