Skip to content

Commit bdaf59d

Browse files
authored
Create minimum-costs-using-the-train-line.py
1 parent 8439427 commit bdaf59d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Time: O(n)
2+
# Space: O(1)
3+
4+
import itertools
5+
6+
7+
# dp
8+
class Solution(object):
9+
def minimumCosts(self, regular, express, expressCost):
10+
"""
11+
:type regular: List[int]
12+
:type express: List[int]
13+
:type expressCost: int
14+
:rtype: List[int]
15+
"""
16+
result = []
17+
dp = [0, expressCost] # dp[0]: min cost of regular route to curr stop, dp[1]: min cost of express route to curr stop
18+
for r, e in itertools.izip(regular, express):
19+
dp = [min(dp[0]+r, dp[1]+e), min(dp[0]+(r+expressCost), dp[1]+e)]
20+
result.append(min(dp[0], dp[1]))
21+
return result

0 commit comments

Comments
 (0)