forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_2073.java
27 lines (25 loc) · 813 Bytes
/
_2073.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package com.fishercoder.solutions;
import java.util.Deque;
import java.util.LinkedList;
public class _2073 {
public static class Solution1 {
public int timeRequiredToBuy(int[] tickets, int k) {
int time = 0;
Deque<int[]> queue = new LinkedList<>();
for (int i = 0; i < tickets.length; i++) {
queue.addLast(new int[]{tickets[i], i});
}
while (!queue.isEmpty()) {
int[] curr = queue.pollFirst();
if (curr[0] - 1 > 0) {
queue.addLast(new int[]{curr[0] - 1, curr[1]});
}
time++;
if (curr[1] == k && curr[0] - 1 == 0) {
return time;
}
}
return time;
}
}
}