File tree Expand file tree Collapse file tree 2 files changed +45
-18
lines changed
Expand file tree Collapse file tree 2 files changed +45
-18
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 89 .1 MB, 시간: 1.57 ms
7+ 메모리: 73 .1 MB, 시간: 1.80 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 07월 14일 12:31:13
19+ 2025년 09월 01일 22:26:05
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 11import java .util .*;
22class Solution {
3+ class Status {
4+ int priority ;
5+ int location ;
6+
7+ public Status (int priority , int location ){
8+ this .priority = priority ;
9+ this .location = location ;
10+ }
11+
12+ @ Override
13+ public String toString (){
14+ return "[" + priority + "," + location +"]" ;
15+ }
16+ }
17+
318 public int solution (int [] priorities , int location ) {
4- PriorityQueue <Integer > pq = new PriorityQueue <>(Collections .reverseOrder ()); // 우선순위 큐(역순)
5- int cnt = 0 ;
6- for (int num : priorities ){
7- pq .add (num ); // 큐에 값 등록
19+ Queue <Status > queue = new LinkedList <>();
20+ List <Integer > list = new ArrayList <>();
21+ int i = 0 ;
22+ for (int priority : priorities ){
23+ Status status = new Status (priority ,i ++);
24+ queue .offer (status );
25+ list .add (priority );
826 }
9-
10- while (!pq .isEmpty ()) {
11- for (int i =0 ; i <priorities .length ;i ++){
12- if (pq .peek () == priorities [i ]){
13- pq .poll ();
14- cnt ++;
15-
16- if (location == i ){
17- return cnt ;
18- }
19- }
27+
28+ // 정렬
29+ Collections .sort (list ,Collections .reverseOrder ());
30+
31+ int cnt = 1 ;
32+ while (!queue .isEmpty ()){
33+ Status status = queue .poll ();
34+ int priority = status .priority ;
35+ int idx = status .location ;
36+ int target = list .get (0 );
37+
38+ if (target == priority ) {
39+ list .remove (0 ); // 삭제
40+ if (location == idx ) return cnt ;
41+ cnt ++;
42+ } else {
43+ queue .offer (status );
2044 }
2145 }
22- return cnt ;
46+
47+
48+ int answer = 0 ;
49+ return answer ;
2350 }
2451}
You can’t perform that action at this time.
0 commit comments