跳转至

根据身高重建队列⚓︎

Leetcode题目链接

描述⚓︎

详见中文题目链接

解答⚓︎

class Solution {
public:
    vector<vector<int>> reconstructQueue(vector<vector<int>>& people) {
        sort(people.begin(), people.end(), [](vector<int>& lhs, vector<int>& rhs) {
            if (lhs[0] != rhs[0]) return lhs[0] > rhs[0];
            else return lhs[1] < rhs[1];
        });

        vector<vector<int>> res;
        for (int i = 0; i < people.size(); i++) {
            res.insert(res.begin() + people[i][1], people[i]);
        }
        return res;
    }
};