Skip to content

Commit 04d55d0

Browse files
committed
[level 2] Title: 프로세스, Time: 1.10 ms, Memory: 75.5 MB -BaekjoonHub
1 parent 85b055b commit 04d55d0

File tree

2 files changed

+29
-45
lines changed

2 files changed

+29
-45
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-
메모리: 73.1 MB, 시간: 1.80 ms
7+
메모리: 75.5 MB, 시간: 1.10 ms
88

99
### 구분
1010

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

1717
### 제출 일자
1818

19-
2025년 09월 01일 22:26:05
19+
2025년 09월 14일 23:43:35
2020

2121
### 문제 설명
2222

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

0 commit comments

Comments
 (0)