첫 번째

def solution(answers):
    students = [[1, 2, 3, 4, 5], [2, 1, 2, 3, 2, 4, 2, 5], [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]]
    scores = {1: 0, 2: 0, 3: 0}
    max_v = 0
    for i in range(len(answers)):
        for j in range(len(students)):
            if answers[i] == students[j][i % len(students[j])]:
                scores[j + 1] += 1

    for k in range(1, len(scores) + 1):
        if max_v <= scores[k]:
            max_v = scores[k]

    result = list(filter(lambda score: score[1] == max_v, scores.items()))
    result = list(map(lambda score: score[0], result))

    return result

수정 후

def solution(answers):
    students = [[1, 2, 3, 4, 5], [2, 1, 2, 3, 2, 4, 2, 5], [3, 3, 1, 1, 2, 2, 4, 4, 5, 5]]
    scores = [0, 0, 0]
    result = []

    for idx, answer in enumerate(answers):
        for i, a in enumerate(students):
            if answer == a[idx % len(a)]:
                scores[i] += 1

    for idx, score in enumerate(scores):
        if score == max(scores):
            result.append(idx + 1)

    return result

+ Recent posts