더 맵게

108번뇌·2020년 10월 21일

https://school.programmers.co.kr/learn/courses/30/lessons/42626

int answer = 0;
        PriorityQueue<Integer> pq = new PriorityQueue<>();

        for(int i=0; i<scoville.length; i++)
        {
            pq.add(scoville[i]);
        }
        
        while(pq.peek()<K && pq.size()>1)
        {
            answer++;
            int a = pq.poll();
            int b = pq.poll();
            int c = a+2*b;

            pq.add(c);
        }
        if(pq.peek()<K)
        {
            return -1;
        }

        return answer;

익힐것
1. PriorityQueue pq = new PriorityQueue<>();
2. pq.poll(); 제일 앞에꺼 pop하며 해당 내용 반환
3. pq.peek(); 제일 앞에 내용 반환.

profile
내일 아침 눈을 떳을 때, '기대되는 오늘 하루를 만들기 위해' 나는 오늘도 생각하고 고민한다.

0개의 댓글