프로그래머스 [큰 수 만들기]
문제보기

소스코드
class Solution {
public String solution(String number, int k) {
int count = k;
int index = 0;
StringBuilder sb = new StringBuilder(number);
while (count != 0 && index != sb.length() - 1) {
char currentNum = sb.charAt(index);
char nextNum = sb.charAt(index + 1);
if (currentNum >= nextNum) {
index++;
} else {
sb.deleteCharAt(index);
count--;
if (index != 0) {
index--;
}
}
}
// 남아있는 모든 숫자가 같거나 내림차순인 경우
if (count != 0) {
sb.delete(sb.length() - count, sb.length());
}
return sb.toString();
}
}