Notice
Recent Posts
Recent Comments
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- 캐치카페
- 편스토랑
- 데이콘
- 파이썬
- Baekjoon
- 프로그래머스 파이썬
- ChatGPT
- Real or Not? NLP with Disaster Tweets
- Docker
- AI 경진대회
- gs25
- ubuntu
- leetcode
- SW Expert Academy
- 자연어처리
- Git
- 더현대서울 맛집
- github
- Kaggle
- 맥북
- hackerrank
- programmers
- 코로나19
- 금융문자분석경진대회
- 편스토랑 우승상품
- PYTHON
- 백준
- 프로그래머스
- dacon
- 우분투
Archives
- Today
- Total
솜씨좋은장씨
[Programmers] 최빈값 구하기 (Python) 본문
728x90
반응형
코딩 1일 1문제! 오늘의 문제는 프로그래머스의 최빈값 구하기 입니다.
👨🏻💻 코드 ( Solution )
def solution(array):
answer = -1
freq_check = {}
for num in array:
if num not in freq_check:
freq_check[num] = 0
freq_check[num] += 1
freq_items = sorted(freq_check.items(), key=lambda x: (-x[1]))
if (len(freq_items) > 1 and freq_items[0][1] != freq_items[1][1]) or len(freq_items) == 1:
answer = freq_items[0][0]
return answer
'Programming > 코딩 1일 1문제' 카테고리의 다른 글
[BaekJoon] 27327번 : 時間 (Hour) (Python) (0) | 2023.01.31 |
---|---|
[BaekJoon] 27294번 : 몇개고? (Python) (0) | 2023.01.30 |
[Programmers] 2023 KAKAO BLIND RECRUITMENT - 개인정보 수집 유효기간 (Python) (0) | 2023.01.26 |
[BaekJoon] 23809번 : 골뱅이 찍기 - 돌아간 ㅈ (Python) (1) | 2023.01.25 |
[BaekJoon] 26561번 : Population (Python) (0) | 2023.01.24 |
Comments