문제에서 주어진 조건대로 idx번째의 문자를 기준으로 오름차순 정렬하면 된다. 같다면 사전순.
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int idx;
bool compare(string& a, string& b) {
if (a[idx] == b[idx]) return a < b;
return a[idx] < b[idx];
}
vector<string> solution(vector<string> strings, int n) {
idx = n;
sort(strings.begin(), strings.end(), compare);
return strings;
}
훌륭한 글 감사드립니다.