题解 | 队列消数
队列消数
https://www.nowcoder.com/practice/48f6e451ff52440798067b77dc5ea95b
from re import A
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param tickets int整型一维数组
# @param k int整型
# @return int整型
#
class Solution:
def timeRequiredToBuy(self , tickets: List[int], k: int) -> int:
# write code here
t=0
a=[i for i in range(len(tickets))]
while k in a:
b=tickets.pop(0)
c=a.pop(0)
if b>1:
tickets.append(b-1)
a.append(c)
t+=1
return t