이문제를 처음 못풀었다.
그리고 인터넷 해답을 봤다.
#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) { //가장 큰 수 - success
string answer = "";
vector<string> Temp;
for(auto i : numbers)
Temp.push_back(to_string(i));
sort(Temp.begin(), Temp.end(), cmp);
for(auto i:Temp)
answer += i;
return answer;
}
익숙치는 않은 형태이지만,
간결하다. 정말 간결하다.
1. 그리고 sort함수에서 마지막에 정렬 방식을 택할 수 있다는 것을 배웠다.
오늘 회사에서 #include / -> graeter() : 내림차순 활용함.
2. for(auto i : answer)
이런식의 간결한 for문.
3. 역시나 자주쓰는 to_string.
dfs로 풀면 시간초과 나옴
next_permutation 으로 풀어도 시간초과나옴