크게 어렵진 않았다.
sort의 cmp를 +로 구현하면 된다.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(string a, string b)
{
return a + b > b + a;
}
string solution(vector<int> numbers) {
vector<string> temp;
for (int i = 0; i < numbers.size(); i++)
temp.push_back(to_string(numbers[i]));
string answer = "";
sort(temp.begin(), temp.end(), cmp);
if (temp[0] == "0")
return "0";
for (int i = 0; i < temp.size(); i++)
answer += temp[i];
return answer;
}'Coding_Test 연습 > Programmers' 카테고리의 다른 글
| [프로그래머스] (C++) LV2 조이스틱 (0) | 2022.05.23 |
|---|---|
| [프로그래머스] (C++) LV2 소수 찾기 (0) | 2022.05.23 |
| [프로그래머스] (C++) LV2 프린터 (0) | 2022.05.22 |
| [프로그래머스] (C++) LV2 전화번호 목록 (0) | 2022.05.21 |
| [프로그래머스] (C++) LV2 빛의 경로 사이클 (0) | 2022.05.19 |