728x90
문자열 내림차순으로 배치하기
코딩테스트 연습 - 문자열 내림차순으로 배치하기
문자열 s에 나타나는 문자를 큰것부터 작은 순으로 정렬해 새로운 문자열을 리턴하는 함수, solution을 완성해주세요. s는 영문 대소문자로만 구성되어 있으며, 대문자는 소문자보다 작은 것으로 �
programmers.co.kr
문제 설명
.
문제 풀이
소스코드 : C++
#include<iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool comp(char a, char b){return a > b;}
string solution(string s) {
sort(s.begin(), s.end(), comp);
return s;
}
소스코드 : Python
def solution(s):
return ''.join(sorted(s,reverse=True))
728x90
300x250