Skip to content

Commit 0b4e39f

Browse files
authored
Create 2073. Time Needed to Buy Tickets
1 parent b0131f5 commit 0b4e39f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

2073. Time Needed to Buy Tickets

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution {
2+
public:
3+
int timeRequiredToBuy(vector<int>& tickets, int k) {
4+
int ans = 0;
5+
for (int i = 0; i < tickets.size(); i++) {
6+
if (i <= k) {
7+
if (tickets[i] <= tickets[k]) {
8+
ans += tickets[i];
9+
} else {
10+
ans += tickets[k];
11+
}
12+
} else {
13+
if (tickets[i] < tickets[k]) {
14+
ans += tickets[i];
15+
} else {
16+
ans += tickets[k] - 1;
17+
}
18+
}
19+
}
20+
return ans;
21+
}
22+
};

0 commit comments

Comments
 (0)