给定正整数序列 及索引 ,定义初始队列为元素下标序列 \dots,n)" 。 重复以下过程直至索引 对应元素被移除: 取出队首下标 ,耗时 秒; 若 1" ,令 并将 加入队尾; 否则,将其从队列中移除。 返回目标元素被移除时的总耗时。
示例1
输入
[1,1,4,5,1,4],2
输出
13
说明
加载中...
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param k int整型 * @return int整型 */ public int timeRequiredToBuy (int[] tickets, int k) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型vector * @param k int整型 * @return int整型 */ int timeRequiredToBuy(vector
& tickets, int k) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param tickets int整型一维数组 # @param k int整型 # @return int整型 # class Solution: def timeRequiredToBuy(self , tickets , k ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param k int整型 * @return int整型 */ public int timeRequiredToBuy (List
tickets, int k) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param k int整型 * @return int整型 */ function timeRequiredToBuy( tickets , k ) { // write code here } module.exports = { timeRequiredToBuy : timeRequiredToBuy };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param tickets int整型一维数组 # @param k int整型 # @return int整型 # class Solution: def timeRequiredToBuy(self , tickets: List[int], k: int) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param k int整型 * @return int整型 */ func timeRequiredToBuy( tickets []int , k int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param ticketsLen int tickets数组长度 * @param k int整型 * @return int整型 */ int timeRequiredToBuy(int* tickets, int ticketsLen, int k ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param tickets int整型一维数组 # @param k int整型 # @return int整型 # class Solution def timeRequiredToBuy(tickets, k) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param k int整型 * @return int整型 */ def timeRequiredToBuy(tickets: Array[Int],k: Int): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param k int整型 * @return int整型 */ fun timeRequiredToBuy(tickets: IntArray,k: Int): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param k int整型 * @return int整型 */ public int timeRequiredToBuy (int[] tickets, int k) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param k int整型 * @return int整型 */ export function timeRequiredToBuy(tickets: number[], k: number): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param k int整型 * @return int整型 */ func timeRequiredToBuy ( _ tickets: [Int], _ k: Int) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param tickets int整型一维数组 * @param k int整型 * @return int整型 */ pub fn timeRequiredToBuy(&self, tickets: Vec
, k: i32) -> i32 { // write code here } }
[1,1,4,5,1,4],2
13