Skip to content

Commit 6b9cce0

Browse files
committed
[level 2] Title: 프로세스, Time: 1.83 ms, Memory: 87.4 MB -BaekjoonHub
1 parent c547496 commit 6b9cce0

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
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-
메모리: 80.9 MB, 시간: 2.75 ms
7+
메모리: 87.4 MB, 시간: 1.83 ms
88

99
### 구분
1010

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

1717
### 제출 일자
1818

19-
2026년 02월 16일 11:55:18
19+
2026년 02월 16일 12:04:49
2020

2121
### 문제 설명
2222

프로그래머스/2/42587. 프로세스/프로세스.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@
33
class Solution {
44
public int solution(int[] priorities, int location) {
55
Queue<Node> processes = new LinkedList<>();
6+
PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
7+
68

79
for(int i=0; i<priorities.length; i++){
810
processes.offer(new Node(priorities[i], i));
11+
pq.offer(priorities[i]); //우선순위 값 역순 정렬 후 저장
912
}
1013

1114
int count = 0;
@@ -14,24 +17,35 @@ public int solution(int[] priorities, int location) {
1417

1518
Node current = processes.poll();
1619

17-
boolean hasHigher = false;
18-
19-
for(Node node : processes){ //우선순위가 높은 노드 찾기
20-
if(node.priority > current.priority){
21-
hasHigher = true;
22-
break;
23-
}
24-
}
25-
26-
if(hasHigher){ //우선순위가 높은 노드를 찾았을 때, 현재 노드를 뽑지 않고 뒤에 넣음
27-
processes.offer(current);
28-
}else{ //자기 자신이 우선순위가 가장 높다면, 현재 뽑은 노드(자기 자신)를 제거하고 count++
20+
if(current.priority == pq.peek()){ //현재 노드의 우선순위가 가장 높은 경우(pq의 제일 앞쪽의 값과 같음)
21+
pq.poll();
2922
count++;
3023

31-
if(current.index == location){ //현재 노드가 찾던 위치의 노드일때
24+
if(current.index == location){ //현재 노드의 위치가 찾으려는 위치인 경우
3225
return count;
3326
}
27+
}else{
28+
processes.offer(current); //현재 노드보다 우선순위가 높은게 있는 경우, 다시 큐 뒤에 삽입
3429
}
30+
31+
// boolean hasHigher = false;
32+
33+
// for(Node node : processes){ //우선순위가 높은 노드 찾기
34+
// if(node.priority > current.priority){
35+
// hasHigher = true;
36+
// break;
37+
// }
38+
// }
39+
40+
// if(hasHigher){ //우선순위가 높은 노드를 찾았을 때, 현재 노드를 뽑지 않고 뒤에 넣음
41+
// processes.offer(current);
42+
// }else{ //자기 자신이 우선순위가 가장 높다면, 현재 뽑은 노드(자기 자신)를 제거하고 count++
43+
// count++;
44+
45+
// if(current.index == location){ //현재 노드가 찾던 위치의 노드일때
46+
// return count;
47+
// }
48+
// }
3549
}
3650

3751
return count;

0 commit comments

Comments
 (0)