public static int solution(int[] priorities, int location) {
int answer = 0;
Queue<Integer> q = new LinkedList<>(); // 중요도
Queue<Integer> q2 = new LinkedList<>(); // 순서
Queue<Integer> q3 = new LinkedList<>();
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
int max = 0;
for (int i = 0; i < priorities.length; i++) {
if (!pq.contains(priorities[i])) {
pq.add(priorities[i]);
}
q.add(priorities[i]);
q2.add(i);
}
max = pq.poll();
while (!q.isEmpty()) {
if (max == q.peek()) {
System.out.println(q2.peek() + " " + q.peek());
q3.add(q2.poll());
q.poll();
} else if (max > q.peek()) {
int tmp = q.poll();
int tmp2 = q2.poll();
q.add(tmp);
q2.add(tmp2);
}
if(!q.contains(max) && !pq.isEmpty()) {
max = pq.poll();
}
}
int cnt = 1;
while (!q3.isEmpty()) {
//System.out.println(q3.poll());
if(q3.poll() == location) {
break;
}
cnt ++;
}
answer = cnt;
return answer;
}
잘 안되면 다른 사람 풀이를 봐야하거늘 ... 똥고집으로 인해 몇시간이 걸려도 자꾸 풀어보게 된다 ㅠ 통과 후 다른사람들 풀이를 보니 아직 한참 모자라구나 싶기도 하지만 그래도 스스로 풀었으니 그걸로 만족하고 더 배워나간다 (๑˃̵ᴗ˂̵)و(๑˃̵ᴗ˂̵)و
나는 총 세개의 큐를 만들었다. 해쉬를 사용해 키,밸류로 순서와 중요도를 넣을까 했는데 넣고 빼기와 비교가 쉽지 않아서 패스..
우선순위 큐에 중복없이 중요도를 다 넣고, 중요도와 일치할때만 최종 큐에 담아주고 그외에는 계속 뒤로 보내주었다.
다른 사람 풀이를 보니 아예 location 을 건드려서 풀었던데 도대체 그런 생각은 어떻게 나오는지 대단 ...
이건 고뇌의 흔적