Skip to content

Commit fb3eec9

Browse files
authored
Merge pull request #1455 from AlgorithmWithGod/LiiNi-coder
[20251119] PGM / LV2 / 택배상자 / 이인희
2 parents 525393a + 1239491 commit fb3eec9

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public int solution(int[] order) {
6+
int answer = 0;
7+
Queue<Integer> main = new LinkedList<>();
8+
for(int i = 1; i <= order.length; i++)
9+
main.offer(i);
10+
11+
Deque<Integer> sub = new ArrayDeque<>();
12+
int index = 0;
13+
14+
for(int target : order){
15+
while(true){
16+
if(!main.isEmpty() && main.peek() <= target){
17+
if(main.peek() == target){
18+
main.poll();
19+
answer++;
20+
21+
break;
22+
} else {
23+
sub.offer(main.poll());
24+
}
25+
} else {
26+
if(!sub.isEmpty() && sub.peek() == target){
27+
sub.poll();
28+
answer++;
29+
}
30+
31+
32+
else {
33+
return answer;
34+
}
35+
break;
36+
}
37+
}
38+
}
39+
return answer;
40+
}
41+
}
42+
43+
```

0 commit comments

Comments
 (0)