题解 | #排队购票#
排队购票
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; } };