From 5e310acac379f0b2e321d3d53bec979bd4934a85 Mon Sep 17 00:00:00 2001 From: ferozsun Date: Fri, 20 Oct 2023 11:47:57 +0900 Subject: [PATCH] Create 1-8_Vote.py --- 1-8_Vote.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 1-8_Vote.py diff --git a/1-8_Vote.py b/1-8_Vote.py new file mode 100644 index 0000000..bc27645 --- /dev/null +++ b/1-8_Vote.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# UTF-8 encoding when using korean + +def solution(N, votes): + vote_counter = [0 for i in range(N+1)] + for i in votes: + vote_counter[i] += 1 + + max_val = max(vote_counter) + + answer = [] + for idx in range(1, N + 1): + if vote_counter[idx] == max_val: + answer.append(idx) + return answer + +N1 = 5 +votes1 = [1,5,4,3,2,5,2,5,5,4] +ret1 = solution(N1, votes1) + +print("solution 함수의 반환 값은", ret1, "입니다.") + +N2 = 4 +votes2 = [1, 3, 2, 3, 2] +ret2 = solution(N2, votes2) + +print("solution 함수의 반환 값은", ret2, "입니다.")