반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- level1
- 구현
- 프로그래머스
- 가상메모리
- programmers
- MYSQL
- 에라스토테네스의 체
- 가상메모리 관리
- 파이썬
- level0
- 그리디
- python
- 다익스트라
- 다이나믹 프로그래밍
- 재귀
- 브루트포스
- BOJ
- N과M
- 수학
- 힙
- BFS
- 스택
- 코딩테스트
- 운영체제
- dfs
- 딕셔너리
- level3
- level2
- 백준
- DP
Archives
- Today
- Total
동캄의 코딩도장
프로그래머스 level0 [최빈값 구하기] 파이썬 본문
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/120812
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
#파이썬 최빈값 구하기
import collections
def solution(array):
answer=collections.Counter(array).most_common(2)
if len(answer)==1:
answer=answer[0][0]
elif answer[0][1]==answer[1][1]:
answer=-1
else:
answer=answer[0][0]
return answer
Counter 함수를 이용해서 최빈값을 구한다.
반응형
'코테 > 프로그래머스 level0' 카테고리의 다른 글
프로그래머스 level0 [특이한 정렬] 파이썬 (0) | 2023.03.05 |
---|---|
프로그래머스 level0 [다항식 더하기] 파이썬 (0) | 2023.03.05 |
프로그래머스 level0 [OX퀴즈] 파이썬 (0) | 2023.03.05 |
프로그래머스 level0 [분수의 덧셈] 파이썬 (0) | 2023.03.05 |
프로그래머스 level0 [연속된 수의 합] 파이썬 (0) | 2023.03.05 |