class Solution {
public:
/**
* 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
*
*
* @param tickets int整型vector
* @param k int整型
* @return int整型
*/
int timeRequiredToBuy(vector<int>& tickets, int k) {
queue<int>count;int n{0};
for (int i=0; i<tickets.size();i++) {
count.push(i);
}// write code here
while (1) {
int temp;temp=count.front();n++;
if (tickets[temp]==1) {
if (temp==k) {
break;
}else {
count.pop();
}
}else {
count.push(count.front());count.pop();tickets[temp]--;
}
}
return n;
}
};

京公网安备 11010502036488号