그리디라 쓰여있어서 쉬웠던 문제.
아니었으면 완전탐색으로 먼저 풀었을꺼같다.
#include <string>
#include <vector>
using namespace std;
string solution(string number, int k) {
string answer = "";
int ind = -1;
for (int i = 0; i < number.size() - k; i++)
{
char max_n = ' ';
for(int j = ind + 1; j <= k + i; j++)
if (max_n < number[j])
{
ind = j;
max_n = number[j];
}
answer += max_n;
}
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV2 피로도 (0) | 2022.06.01 |
|---|---|
| [프로그래머스] (C++) LV2 2 x n 타일링 (0) | 2022.05.31 |
| [프로그래머스] (C++) LV2 카펫 (0) | 2022.05.28 |
| [프로그래머스] (C++) LV2 H-Index (0) | 2022.05.28 |
| [프로그래머스] (C++) LV2 다리를 지나는 트럭 (0) | 2022.05.26 |