❓문제


🤔 풀기 전
문제점
- 최대 10,000 문제로 구성되어 있다 해서 for문을 사용해도 런타임에러가 안날 것이라고 생각했는데 런타임에러가 났다. 왜?
-> 당연. 수포자들의 패턴을 반복해서 비교해야했는데 반복하지 않고 한번에 끝냈다.
🙋🏻♀️ 내 코드
def solution(answers):
answer = []
supoja = [[1, 2, 3, 4, 5],
[2, 1, 2, 3, 2, 4, 2, 5],
[3, 3, 1, 1, 2, 2, 4, 4, 5, 5]]
corrCount = [0, 0, 0]
qCount = len(answers)
for i in range(qCount):
q = answers[i]
if q == supoja[0][i%5]:
corrCount[0] += 1
if q == supoja[1][i%8]:
corrCount[1] += 1
if q == supoja[2][i%10]:
corrCount[2] += 1
maxCount = max(corrCount)
for i in range(3):
if maxCount == corrCount[i]:
answer.append(i+1)
answer.sort()
return answer
answers = [1,3,2,4,2]
print(solution(answers))
배운점