250823

lililllilillll·2025년 8월 23일

개발 일지

목록 보기
272/350

✅ 한 것들


  • 프로그래머스
  • NHN Pre-test 1 : 3/3솔
    • while문에서 and가 아니라 or로 하는 실수 해서 무한 반복문 생성한 실수


⚔️ 프로그래머스


더 맵게

int solution(vector<int> scoville, int K) {
    int answer = 0;
    // 힙에 다 넣는다
    // 힙에서 빼낸게 K 이상일 때까지 돌린다
    // 두 개 섞고 다시 넣는다
    
    priority_queue<int, vector<int>, greater<int>> pq;
    for(int s : scoville) pq.push(s);
    
    while(pq.top() < K && pq.size() > 1)
    {
        int e1 = pq.top(); pq.pop();
        int e2 = pq.top(); pq.pop();
        int ne = e1 + 2 * e2;
        pq.push(ne);
        answer++;
    }
    
    if(pq.top() < K) return -1;
    
    return answer;
}


profile
너 정말 **핵심**을 찔렀어

0개의 댓글