Problem Solving/Programmers
[Level 2] 큰 수 만들기
kmkunk
2022. 4. 6. 12:51
class Solution {
public String solution(String number, int k) {
String answer = "";
int len = number.length()-k;
for(int i=0; i<number.length(); i++) {
if(answer.length()==len) { break; }
if(k==0) { return answer+number.substring(i, number.length()); }
char c = number.charAt(i);
boolean delete = true;
for(int j=i+1; j<=i+k; j++) {
if(c<number.charAt(j)) {
delete = false;
k--;
break;
}
}
if(delete) { answer += String.valueOf(c); }
}
return answer;
}
}