title: "[프로그래머스] 최빈값 구하기 Python 파이썬 해설 (Level 0) - 이도훈"
cleanUrl: "programmers/120812"
description: "프로그래머스 Level 0 문제 [최빈값 구하기]의 풀이를 정리합니다."
from collections import Counter
def solution(array):
cntr = Counter(array)
if len(cntr) == 1:
return list(cntr.keys())[0]
common = cntr.most_common(2)
if common[0][1] == common[1][1]:
return -1
else:
return common[0][0]
프로그래머스 코딩테스트 연습 https://school.programmers.co.kr/learn/challenges