문자열 내림차순으로 배치하기

magicdrill·2024년 3월 7일
0

문자열 내림차순으로 배치하기

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

using namespace std;

string solution(string s) 
{
    string answer = "";
    int i, length = s.length();
    vector <char> temp;
    
    for(i = 0; i< length; i++)
    {
        temp.push_back(s[i]);
    }
    sort(temp.begin(), temp.end(), greater<char>());
    for(i = 0; i < length; i++)
    {
        answer+= temp[i];
    }
    
    return answer;
}

0개의 댓글