
람다 함수로 사용자 설정 정의해 정렬하기
·
공부/Code Cata
#include #include #include using namespace std;vector solution(vector strings, int n) { sort(strings.begin(), strings.end(), [n](const string& a, const string& b) { if(a[n] == b[n]) { return a 비교할 인덱스 값 n을 capture해서 람다 함수로 넘겨주어 두 인덱스의 값이 같다면 사전순으로 정렬하고, 같지 않다면 바로 오름차순 정렬하였다. 람다함수[capture](parameters) -> return_type { // function body};capture: 람다 함수 외부의 변수를 가져오는 방식..