on
프로그래머스 프린터(자바)
프로그래머스 프린터(자바)
728x90
import java.util.LinkedList; import java.util.PriorityQueue; import java.util.Queue; class Solution { public static int solution(int[] priorities, int location) { int answer = 1; Queue q = new LinkedList<>(); PriorityQueue pq = new PriorityQueue<>(); for (int i = 0; i < priorities.length; i++) { Printer pt = new Printer(i,priorities[i]); pq.add(pt); q.add(pt); } while(!q.isEmpty()){ Printer nowPt = q.poll(); if (pq.peek().value == nowPt.value) { pq.poll(); if(nowPt.idx==location){ break; } answer++; } else{ q.add(nowPt); } } return answer; } } class Printer implements Comparable{ int idx; int value; public Printer(int idx, int value) { this.idx = idx; this.value = value; } @Override public int compareTo(Printer o) { return -(this.value - o.value); } }
728x90
from http://arch1tect.tistory.com/167 by ccl(A) rewrite - 2021-09-29 01:27:42