제출 코드
- 사용 알고리즘 :
그리디
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Solution {
public String solution(String number, int k) {
String answer = "";
char[] num = number.toCharArray();
int remain=k, start=0, cnt=number.length()-k;
while(remain>0){
int max = start;
for(int i=start+1; i<=start+remain; i++){
if(num[max] < num[i]) max = i;
}
answer += num[max];
remain -= max-start;
start = max+1;
if(--cnt==0) return answer;
}
return answer + number.substring(start);
}
}