Skip to content

Commit c5add92

Browse files
authored
Create buy-passes.py
1 parent 18f0c75 commit c5add92

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

buy-passes.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class Solution:
2+
"""
3+
@param arr: the line
4+
@param k: Alex place
5+
@return: the time when Alex requires to buy all passes
6+
"""
7+
def buyPasses(self, arr, k):
8+
# Write your code here.
9+
r = 0
10+
for i in range(len(arr)):
11+
if i <= k:
12+
r += min(arr[i], arr[k])
13+
else:
14+
r += min(arr[k] - 1, arr[i])
15+
return r
16+
17+
'''
18+
arr = [1, 2, 5] means they want 1, 2, 5 tickets.
19+
k = 1 means Alex is user 1 who needs 2 tickets.
20+
'''
21+
22+
# medium: https://www.lintcode.com/problem/1851/

0 commit comments

Comments
 (0)