Queue Reconstruction by Height

 

CREATED TIME: Jan 19, 2020 4:06 PM UPDATED TIME: Jan 19, 2020 4:06 PM 난이도: Medium

bool cmp(const vector &a, const vector&b){ if(a[0] != b[0]){ return a[0] > b[0]; }else{ return a[1] < b[1]; } }

class Solution {
public:
    vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
        sort(people.begin(), people.end(), cmp);
        vector<vector<int>> res;
        for(auto &a : people){
            res.insert(res.begin()+a[1], a);
        }
        return res;
    }
};