Skip to content

Commit d15420f

Browse files
committed
[level 2] Title: 프로세스, Time: 1.80 ms, Memory: 73.1 MB -BaekjoonHub
1 parent 68de2d4 commit d15420f

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

프로그래머스/2/42587. 프로세스/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
### 성능 요약
66

7-
메모리: 89.1 MB, 시간: 1.57 ms
7+
메모리: 73.1 MB, 시간: 1.80 ms
88

99
### 구분
1010

@@ -16,7 +16,7 @@
1616

1717
### 제출 일자
1818

19-
2025년 07월 14일 12:31:13
19+
2025년 09월 01일 22:26:05
2020

2121
### 문제 설명
2222

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,51 @@
11
import java.util.*;
22
class 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
}

0 commit comments

Comments
 (0)