Leetcode / 2073. Time Needed to Buy Tickets
Pick a programming language:
Here is the source code for the solution to this problem.
class Solution {
public int timeRequiredToBuy(int[] tickets, int k) {
int i = 0;
int count = 0;
while (tickets[k] > 0) {
if (tickets[i] > 0) {
tickets[i]--;
count++;
};
if (i + 1 >= tickets.length) {
i = 0;
} else {
i++;
}
}
return count;
}
}
Did you like the lesson? 😆👍
Consider a donation to support our work: