숫자 배열이 주어지고 각 숫자들을 재 배치 해서 가장 큰 수를 return 하는 문제
간단한 정렬 문제이다.
C++ 의 algorithm 라이브러리 안에 next_permutation 을 사용하여 순열을 구하고 그 중에 가장 큰 수를 찾는 방식을 택했다.
시간 초과는 나지 않았으나 core_dumped 오류가 발생 되었다.
파이썬의 itertools와 같이 왠만하면 사용안하고 구현을 먼저해보는게..
#include <string>
#include <vector>
using namespace std;
bool sort_def(string a,string b){
return a+b>b+a;
}
string solution(vector<int> numbers) {
string answer = "";
int max = 0;
vector<string> sv;
for(auto idx:numbers){
sv.push_back(to_string(idx));
}
sort(sv.begin(),sv.end(),sort_def);
if(sv.at(0)=="0")return "0";
for(auto c:sv){
answer+=c;
}
return answer;
}