zoukankan      html  css  js  c++  java
  • 406. Queue Reconstruction by Height

    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;
        }
    };
  • 相关阅读:
    MyBatis
    JavaAgent
    Intellij IDEA
    SVN安装总结
    git(笔记)
    springboot面试题
    spring总结
    springmvc总结
    jdbc链接数据库
    redis面试题
  • 原文地址:https://www.cnblogs.com/ymjyqsx/p/10498795.html
Copyright © 2011-2022 走看看