0406.cpp (427B)
1 class Solution { 2 public: 3 vector<vector<int>> reconstructQueue(vector<vector<int>> &people) { 4 sort(begin(people), end(people), 5 [](const auto &a, const auto &b) { return a[0] > b[0] || (a[0] == b[0] && a[1] < b[1]); }); 6 vector<vector<int>> res; 7 res.reserve(people.size()); 8 for (const auto &p : people) 9 res.insert(res.begin() + p[1], p); 10 return res; 11 } 12 };