https://programmers.co.kr/learn/courses/30/lessons/42883
그리디는 아직 저한테 버거운것 같습니다..
풀다가 다른 분들의 풀이를 참고했습니다.
class Solution {
public String solution(String number, int k) {
StringBuilder stringBuilder = new StringBuilder();
int idx = -1;
char max;
for(int i=0; i< number.length()-k; i++){
max = '0';
for(int j= idx+1; j<=i+k; j++){
if(max < number.charAt(j)){
max = number.charAt(j);
idx = j;
}
}
stringBuilder.append(max);
}
return stringBuilder.toString();
}
}
'알고리즘' 카테고리의 다른 글
백준 17144번 - 미세먼지 안녕!(런타임 에러) (0) | 2020.04.26 |
---|---|
프로그래머스 - 구명보트 (0) | 2020.04.17 |
프로그래머스 - 라면공장 (0) | 2020.04.12 |
프로그래머스 - 조이스틱(오답) (0) | 2020.04.12 |
프로그래머스 - H - index (0) | 2020.04.12 |