首页 > 其他 > 详细

406. Queue Reconstruction by Height

时间:2019-03-08 23:34:43      阅读:202      评论:0      收藏:0      [点我收藏+]

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!