문제 링크: 코딩테스트 연습 > 정렬 > 가장 큰 수
문제 이해
알고리즘 구현
알고리즘
#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) {
string answer = "";
vector<string> numstrs;
for (auto num: numbers)
numstrs.push_back(to_string(num));
sort(numstrs.begin(), numstrs.end(), cmp);
if (numstrs[0][0] == '0') return "0";
for (auto str: numstrs)
answer += str;
return answer;
}