Skip to content

Commit 95ee074

Browse files
authored
Create minimum-cost-to-set-cooking-time.py
1 parent 0958822 commit 95ee074

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Time: O(1)
2+
# Space: O(1)
3+
4+
# simulation
5+
class Solution(object):
6+
def minCostSetTime(self, startAt, moveCost, pushCost, targetSeconds):
7+
"""
8+
:type startAt: int
9+
:type moveCost: int
10+
:type pushCost: int
11+
:type targetSeconds: int
12+
:rtype: int
13+
"""
14+
def cost(m, s):
15+
if not (0 <= m <= 99 and s <= 99):
16+
return float("inf")
17+
result = 0
18+
curr = startAt
19+
for x in map(int, list(str(m*100 + s))):
20+
result += (moveCost if x != curr else 0)+pushCost
21+
curr = x
22+
return result
23+
24+
m, s = divmod(targetSeconds, 60)
25+
return min(cost(m, s), cost(m-1, s+60))

0 commit comments

Comments
 (0)