We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
package main.java.com.poogle.PG.Q42587; import java.util.LinkedList; import java.util.Queue; public class Solution { public static void main(String[] args) { System.out.println(solution(new int[]{2, 1, 3, 2}, 2)); } private static int solution(int[] priorities, int location) { int answer = 0; Queue<Printer> queue = new LinkedList<>(); for (int i = 0; i < priorities.length; i++) { queue.offer(new Printer(i, priorities[i])); } while (!queue.isEmpty()) { boolean flag = false; int now = queue.peek().prior; for (Printer p : queue) { if (now < p.prior) flag = true; } if (flag) { queue.offer(queue.poll()); } else { if (queue.poll().location == location) { answer = priorities.length - queue.size(); } } } return answer; } static class Printer { int location; int prior; public Printer(int location, int prior) { this.location = location; this.prior = prior; } } }
The text was updated successfully, but these errors were encountered:
58f4af7
suhyunsim
No branches or pull requests
문제
핵심 아이디어
어려운 점, 실수
풀이
The text was updated successfully, but these errors were encountered: