Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

12-kokeunho #45

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions kokeunho/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
| 9μ°¨μ‹œ | 2024.11.26 | λ‹€μ΄λ‚˜λ―Ή ν”„λ‘œκ·Έλž˜λ° | [계단 였λ₯΄κΈ°](https://www.acmicpc.net/problem/2579) | [#33](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/33) |
| 10μ°¨μ‹œ | 2024.11.30 | 자료ꡬ쑰 | [κ°€μš΄λ°λ₯Ό λ§ν•΄μš”](https://www.acmicpc.net/problem/1655) | [#36](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/36) |
| 11μ°¨μ‹œ | 2024.12.21 | 그리디 μ•Œκ³ λ¦¬μ¦˜ | [νšŒμ˜μ‹€ λ°°μ •](https://www.acmicpc.net/problem/1931) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/43) |
| 12μ°¨μ‹œ | 2024.12.25 | 그리디 μ•Œκ³ λ¦¬μ¦˜ | [크게 λ§Œλ“€κΈ°](https://www.acmicpc.net/problem/2812) | [#45](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/45) |
---
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package org.example;

import java.util.*;

public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
String num = sc.next();

Stack<Character> stack = new Stack<>();

int count = 0;

for(int i = 0; i < n; i++) {
char c = num.charAt(i);
while(!stack.isEmpty() && count < k && stack.peek() < c) {
stack.pop();
count++;
}
stack.push(c);
}

StringBuilder result = new StringBuilder();
for(int i = 0; i < n - k; i++) {
result.append(stack.get(i));
}
Comment on lines +26 to +28
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

μœ„μ˜ for문을 보고 λ‚΄λ¦Όμ°¨μˆœμœΌλ‘œ μ •λ ¬λœ μˆ˜λŠ” μ˜¬λ°”λ₯΄κ²Œ μ œκ±°ν•˜μ§€ λͺ»ν•˜μ§€ μ•Šλ‚˜? 라고 μƒκ°ν–ˆμ—ˆλŠ”λ° n-kκΉŒμ§€λ§Œ 좜λ ₯ν•˜μ—¬ μžμ—°μŠ€λ ˆ μ œκ±°ν•˜μ…¨λ„€μš”! μ €λŠ” 반볡문 ν•œλ²ˆ 더 μΌλŠ”λ° 이 방법이 더 νš¨μœ¨μ μΈκ²ƒ κ°™μŠ΅λ‹ˆλ‹€. πŸ‘ πŸ‘

System.out.println(result.toString());

}
}
Loading