Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4c0c819

Browse files
add 2073
1 parent efef008 commit 4c0c819

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2073|[Time Needed to Buy Tickets](https://leetcode.com/problems/time-needed-to-buy-tickets/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2073.java) ||Easy||
1112
|2070|[Most Beautiful Item for Each Query](https://leetcode.com/problems/most-beautiful-item-for-each-query/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2070.java) ||Medium||
1213
|2068|[Check Whether Two Strings are Almost Equivalent](https://leetcode.com/problems/check-whether-two-strings-are-almost-equivalent/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2068.java) ||Easy||
1314
|2063|[Vowels of All Substrings](https://leetcode.com/problems/vowels-of-all-substrings/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2063.java) ||Medium||
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Deque;
4+
import java.util.LinkedList;
5+
6+
public class _2073 {
7+
public static class Solution1 {
8+
public int timeRequiredToBuy(int[] tickets, int k) {
9+
int time = 0;
10+
Deque<int[]> queue = new LinkedList<>();
11+
for (int i = 0; i < tickets.length; i++) {
12+
queue.addLast(new int[]{tickets[i], i});
13+
}
14+
while (!queue.isEmpty()) {
15+
int[] curr = queue.pollFirst();
16+
if (curr[0] - 1 > 0) {
17+
queue.addLast(new int[]{curr[0] - 1, curr[1]});
18+
}
19+
time++;
20+
if (curr[1] == k && curr[0] - 1 == 0) {
21+
return time;
22+
}
23+
}
24+
return time;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)