Skip to content

Commit 2c1ff7e

Browse files
authored
Merge pull request #1435 from AlgorithmWithGod/ksinji
[20251117] PGM / LV2 / 큰 수 만들기 / 강신지
2 parents ab81096 + df20190 commit 2c1ff7e

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
```java
2+
class Solution {
3+
public String solution(String number, int k) {
4+
StringBuilder stack = new StringBuilder();
5+
6+
for (int i = 0; i < number.length(); i++) {
7+
char c = number.charAt(i);
8+
9+
while (k > 0 && stack.length() > 0 && stack.charAt(stack.length() - 1) < c) {
10+
stack.deleteCharAt(stack.length() - 1);
11+
k--;
12+
}
13+
stack.append(c);
14+
}
15+
16+
if (k > 0) {
17+
stack.setLength(stack.length() - k);
18+
}
19+
20+
return stack.toString();
21+
}
22+
}
23+
```

0 commit comments

Comments
 (0)