5 lines C++ solution


  • 0
    F
    class Solution {
    public:
        vector<pair<int, int>> reconstructQueue(vector<pair<int, int>>& people) {
            sort(people.begin(),people.end(),[](pair<int,int>x,pair<int,int>y){return x.first==y.first ? x.second < y.second : x.first > y.first;});
            vector<pair<int, int>> res;
            for(int i = 0; i < people.size(); ++i) res.insert(res.begin()+people[i].second,people[i]);
            return res;
        }
    };
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.