프로그래머스 120880 특이한 정렬

1 개요[ | ]

프로그래머스 120880 특이한 정렬

2 C++[ | ]

#include <string>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> solution(vector<int> numlist, int n) {
    sort(numlist.begin(), numlist.end(), [n](int a, int b) {
        int c = abs(n-a);
        int d = abs(n-b);
        if(c == d) {
            return b < a;
        }
        return c < d;
    });
    return numlist;
}