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


[문제]
https://school.programmers.co.kr/learn/courses/30/lessons/42626
프로그래머스
SW개발자를 위한 평가, 교육의 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[소스 코드]
import java.util.*;
class Solution {
public int solution(int[] scoville, int K) {
int answer = 0;
PriorityQueue<Integer> pq = new PriorityQueue<>();
for(int s : scoville) pq.offer(s);
while(pq.size()>1 && pq.peek()<K){
int a = pq.poll();
int b = pq.poll() * 2;
pq.offer(a+b);
answer++;
}
if(pq.peek()<K) return -1;
return answer;
}
}'Algorithms > Programmers' 카테고리의 다른 글
| [프로그래머스] Lv.2 땅따먹기 (0) | 2025.10.16 |
|---|---|
| [프로그래머스] Lv.2 주식가격 (0) | 2025.10.16 |
| [프로그래머스] Lv.2 [3차] n진수 게임 (0) | 2025.10.16 |
| [프로그래머스] Lv.2 k진수에서 소수 개수 구하기 (0) | 2025.10.16 |
| [프로그래머스] Lv.2 뒤에 있는 큰 수 찾기 (0) | 2025.10.16 |