유형 : 구현
풀이 시간 : 15분
def solution(answers):
one = [1, 2, 3, 4, 5]
two = [2, 1, 2, 3, 2, 4, 2, 5]
three = [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]
x, y, z = 0, 0, 0
for i in range(len(answers)):
if one[0] == answers[i]:
x += 1
if two[0] == answers[i]:
y += 1
if three[0] == answers[i]:
z += 1
one.append(one.pop(0))
two.append(two.pop(0))
three.append(three.pop(0))
res = [x, y, z]
answer = [i+1 for i in range(3) if res[i] == max(res)]
return answer
처음에 똑같이 작성했는데 왜 안됐지..
알고리즘 : queue를 설정하여, 하나씩 대조하며 pop한뒤 뒤에 다시 insert한다.
'프로그래머스 > Lv. 1' 카테고리의 다른 글
38. 소수 만들기 (소수 판별 알고리즘) (0) | 2024.07.16 |
---|---|
37. 과일 장수 (1) | 2024.07.14 |
35. 2016년 (1) | 2024.07.14 |
34. 폰켓몬 (set에 대하여) (0) | 2024.07.14 |
33. 카드 뭉치 (0) | 2024.07.14 |