내 풀이
def solution(answers):
person1 = [1, 2, 3, 4, 5]
person2 = [2, 1, 2, 3, 2, 4, 2, 5]
person3 = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
result = [0, 0, 0]
answer_result = []
for idx, answer in enumerate(answers):
if answer == person1[idx % len(person1)]:
result[0] += 1
if answer == person2[idx % len(person2)]:
result[1] += 1
if answer == person3[idx % len(person3)]:
result[2] += 1
for idx, score in enumerate(result):
if score == max(result):
answer_result.append(idx + 1)
return answer_result
다른 방법
from itertools import cycle
def solution(answers):
giveups = [
cycle([1,2,3,4,5]),
cycle([2,1,2,3,2,4,2,5]),
cycle([3,3,1,1,2,2,4,4,5,5]),
]
scores = [0, 0, 0]
for num in answers:
for i in range(3):
if next(giveups[i]) == num:
scores[i] += 1
highest = max(scores)
return [i + 1 for i, v in enumerate(scores) if v == highest]
'Engineering WIKI > Programmers' 카테고리의 다른 글
[프로그래머스] 예산 (0) | 2022.04.05 |
---|---|
[프로그래머스] 3진법 뒤집기 (0) | 2022.04.05 |
[프로그래머스] 실패율 (0) | 2022.04.02 |
[프로그래머스] 폰켓몬 (0) | 2022.04.01 |
[프로그래머스] 소수 만들기 (0) | 2022.04.01 |
[프로그래머스] 내적 (0) | 2022.04.01 |
[프로그래머스] 음양 더하기 (0) | 2022.04.01 |
[프로그래머스] 없는 숫자 더하기 (0) | 2022.04.01 |