https://www.cnblogs.com/grandyang/p/5928417.html
https://www.cnblogs.com/liziran/p/6106534.html
个子高的位置排好后,再怎么对个子矮的排,都不会影响个子高的人的相对位置
贪心的思想
class Solution { public: vector<pair<int, int>> reconstructQueue(vector<pair<int, int>>& people) { sort(people.begin(),people.end(),cmp); for(int i = 0;i < people.size();i++){ if(people[i].second != i){ auto p = people[i]; people.erase(people.begin() + i); people.insert(people.begin() + p.second,p); } } return people; } static bool cmp(pair<int,int> a,pair<int,int> b){ if(a.first > b.first || (a.first == b.first && a.second < b.second)) return true; else return false; } };
406. Queue Reconstruction by Height
原文:https://www.cnblogs.com/ymjyqsx/p/10498795.html