直接做就行了
from typing import List
class Solution:
def timeRequiredToBuy(self, tickets: List[int], k: int) -> int:
time = 0
for i in range(len(tickets)):
time += tickets[k] if tickets[i] > tickets[k] else tickets[i]
if i <= k:
time += tickets[k] if tickets[i] > tickets[k] else tickets[i]
else:
time += tickets[k] - 1 if tickets[i] >= tickets[k] else tickets[i]
return time
def timeRequiredToBuy_2(self, tickets: List[int], k: int) -> int:
time = 0
for i in range(len(tickets)):
if tickets[i] >= tickets[k]:
if i <= k:
time += tickets[k]
else:
time += tickets[k] - 1
else:
time += tickets[i]
return time