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 |
| 31 |
Tags
- oracle
- db
- 운동기록
- DP
- dfs
- 문자열
- priorityqueue
- 백준
- 코테
- binary search
- 알고리즘
- 코딩테스트
- math
- 프로그래머스
- SWEA
- BOJ
- Java
- 문제풀이
- 시뮬레이션
- SQL
- 자바
- MySQL
- 건강
- 이분탐색
- 투포인터
- 문제해결
- 러닝일지
- greedy
- BFS
- COS PRO
Archives
- Today
- Total
슈콩
[프로그래머스] Lv.2 귤 고르기 본문


[문제]
https://school.programmers.co.kr/learn/courses/30/lessons/138476
[소스 코드]
import java.util.*;
class Solution {
public int solution(int k, int[] tangerine) {
int answer = 0;
Map<Integer,Integer> hm = new HashMap<>();
for(int t : tangerine){
hm.put(t,hm.getOrDefault(t,0)+1);
}
List<Integer> list = new ArrayList<>(hm.values());
Collections.sort(list,(a,b)->b-a);
int type = 0;
for(int cnt : list){
k -= cnt;
type++;
if(k<=0) break;
}
return type;
}
}'Algorithms > Programmers' 카테고리의 다른 글
| [프로그래머스] 멀리 뛰기 (0) | 2025.10.14 |
|---|---|
| [프로그래머스] Lv.2 점프와 순간 이동 (0) | 2025.10.14 |
| [프로그래머스] Lv.2 피보나치 수 (0) | 2025.10.13 |
| [프로그래머스] Lv.2 짝지어서 제거하기 (0) | 2025.10.13 |
| [프로그래머스] Lv.2 다음 큰 숫자 (0) | 2025.10.13 |