File tree Expand file tree Collapse file tree 2 files changed +29
-45
lines changed
Expand file tree Collapse file tree 2 files changed +29
-45
lines changed Original file line number Diff line number Diff line change 44
55### 성능 요약
66
7- 메모리: 73.1 MB, 시간: 1.80 ms
7+ 메모리: 75.5 MB, 시간: 1.10 ms
88
99### 구분
1010
1616
1717### 제출 일자
1818
19- 2025년 09월 01일 22:26:05
19+ 2025년 09월 14일 23:43:35
2020
2121### 문제 설명
2222
Original file line number Diff line number Diff line change 11import java .util .*;
2+
23class 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-
184 public int solution (int [] priorities , int location ) {
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 );
5+ int answer = 0 ;
6+ int l = location ;
7+
8+ Queue <Integer > que = new LinkedList <Integer >();
9+ for (int i : priorities ){
10+ que .add (i );
2611 }
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 );
12+
13+ Arrays .sort (priorities );
14+ int size = priorities .length -1 ;
15+
16+
17+
18+ while (!que .isEmpty ()){
19+ Integer i = que .poll ();
20+ if (i == priorities [size - answer ]){
21+ answer ++;
22+ l --;
23+ if (l <0 )
24+ break ;
25+ }else {
26+ que .add (i );
27+ l --;
28+ if (l <0 )
29+ l =que .size ()-1 ;
4430 }
4531 }
46-
47-
48- int answer = 0 ;
32+
4933 return answer ;
5034 }
51- }
35+ }
You can’t perform that action at this time.
0 commit comments