题解 | #排队购票#

排队购票

https://www.nowcoder.com/practice/44f07b72cd574485b0296a40eca83215

struct mypair{
    int id;
    int time;
    mypair(int a, int b):id(a), time(b){;}
    bool operator<(const mypair other) const{
        return (this->time < other.time);
    }
};
bool compare(mypair& a,  mypair& b){
    return a.time > b.time;
}

class Solution {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
     *
     * 
     * @param numTickets int整型 
     * @param visitorTimes int整型vector 
     * @return int整型vector
     */
    vector<int> ticketQueue(int numTickets, vector<int>& visitorTimes) {
        // write code here
        list<mypair> mymap;
        for(int i = 1; i < numTickets + 1; ++i){
            mymap.push_back(mypair(i, visitorTimes[i-1]));
        }

        mymap.sort();
        vector<int> res;
        for(auto it:mymap) res.push_back(it.id);
        return res;
    }
};

全部评论

相关推荐

秋盈丶:后续:我在宿舍群里和大学同学分享了这事儿,我好兄弟气不过把他挂到某脉上了,10w+阅读量几百条评论,直接干成精品贴子,爽
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务