[프로그래머스/C++] 가장 큰 수

mani·2023년 4월 13일
0

가장 큰 수

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

bool comp(string a, string b){
    return a+b>b+a;
}

string solution(vector<int> numbers) {
    string answer = "";
    
    vector<string> num_v;
    
    for(auto ele:numbers)
        num_v.push_back(to_string(ele));
    
    sort(num_v.begin(), num_v.end(), comp);
    
    for(auto ele:num_v)
        answer +=ele;
    
    if(answer[0]=='0') answer = "0";
    
    return answer;
}
profile
log

0개의 댓글