public class NUM42883 {
public static void main(String[] args) {
String number = "98765";
int k = 3;
System.out.println(solution(number, k));
}
public static String solution(String number, int k) {
String answer = "";
Stack<Character> stack = new Stack<>();
for (int i = 0; i < number.length(); i++) {
char c = number.charAt(i);
while (!stack.isEmpty() && stack.peek() < c && k > 0) {
stack.pop();
k--;
}
stack.push(c);
}
Iterator<Character> iterator = stack.iterator();
while(iterator.hasNext() && answer.length() < number.length() - k) { answer += iterator.next(); }
return answer;
}
}
*다른 분들의 코드를 참고하여 작성했습니다