📌문제
https://programmers.co.kr/learn/courses/30/lessons/42840
🎖️난이도
Level 1
✔️풀이
# sol1
def solution(answers):
one = [1,2,3,4,5] * 2000
two = [2,1,2,3,2,4,2,5] * 1250
three = [3,3,1,1,2,2,4,4,5,5] * 1000
scores = [0, 0, 0]
l = len(answers)
for i in range(l):
if answers[i] == one[i]:
scores[0] += 1
if answers[i] == two[i]:
scores[1] += 1
if answers[i] == three[i]:
scores[2] += 1
tmp_max = max(scores)
persons = [i+1 for i in range(3) if scores[i] == tmp_max]
return persons
# sol2) pattern & %(나머지) 연산자 사용
def solution(answers):
pattern1 = [1,2,3,4,5]
pattern2 = [2,1,2,3,2,4,2,5]
pattern3 = [3,3,1,1,2,2,4,4,5,5]
score = [0, 0, 0]
result = []
for idx, answer in enumerate(answers):
if answer == pattern1[idx%len(pattern1)]:
score[0] += 1
if answer == pattern2[idx%len(pattern2)]:
score[1] += 1
if answer == pattern3[idx%len(pattern3)]:
score[2] += 1
for idx, s in enumerate(score):
if s == max(score):
result.append(idx+1)
return result
'[ 알고리즘 ] > Brute Force' 카테고리의 다른 글
[백준] 1759. 암호 만들기 (0) | 2022.07.02 |
---|---|
[프로그래머스] 두 개 뽑아서 더하기 (0) | 2022.07.02 |
[프로그래머스] 카펫 (0) | 2022.06.29 |
[프로그래머스] 소수 찾기 (0) | 2022.06.29 |
[백준] 11504. 돌려 돌려 돌림판! (0) | 2022.06.29 |