题目描述
blablabla
样例
blablabla
import java.util.*;
class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char[] ch = sc.nextLine().toCharArray();
Deque[HTML_REMOVED] stack = new ArrayDeque<>();
int k = sc.nextInt();
if (ch.length == 0) System.out.print(0);
for (int i = 0; i < ch.length; i++) {
while (!stack.isEmpty() && stack.peek() > ch[i] && k > 0) {
stack.pop();
k–;
}
stack.push(ch[i]);
}
while (k > 0 && !stack.isEmpty()) {
stack.pop();
k–;
}
Deque[HTML_REMOVED] deque = new ArrayDeque<>();
while (!stack.isEmpty()) deque.push(stack.pop());
StringBuilder sb = new StringBuilder();
while (!deque.isEmpty()) {
char c = deque.pop();
if (c == ‘0’ && sb.length() == 0) continue;
sb.append(c);
}
if (sb.length() == 0) {
System.out.print(0);
} else {
System.out.print(sb.toString());
}
}
}
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla