Skip to content

Commit 52ea32e

Browse files
authored
[20251122] PGM / LV2 / 큰 수 만들기 / 이인희
1 parent 33d3e13 commit 52ea32e

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
```java
2+
import java.util.*;
3+
4+
class Solution {
5+
public String solution(String number, int k) {
6+
int len = number.length() - k;
7+
8+
Deque<Character> stack = new ArrayDeque<>();
9+
10+
for(int i = 0; i < number.length(); i++){
11+
char c = number.charAt(i);
12+
13+
while(!stack.isEmpty()){
14+
if(k<=0 || stack.peekLast() >= c)
15+
break;
16+
stack.pollLast();
17+
k--;
18+
}
19+
stack.offerLast(c);
20+
}
21+
22+
while(stack.size() > len){
23+
stack.pollLast();
24+
}
25+
StringBuilder sb = new StringBuilder();
26+
while(!stack.isEmpty()){
27+
sb.append(stack.pollFirst());
28+
}
29+
return sb.toString();
30+
}
31+
}
32+
33+
```

0 commit comments

Comments
 (0)