From 0a72ae1b78401acb78d403e8328320370d9c2f28 Mon Sep 17 00:00:00 2001 From: Sapan Desai <35861214+sapan17@users.noreply.github.com> Date: Wed, 28 Oct 2020 11:52:54 +0530 Subject: [PATCH] Create Min Cost Climbing Stairs.py Once you pay the cost, you can either climb one or two steps. You need to find the minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1. --- Min Cost Climbing Stairs.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 Min Cost Climbing Stairs.py diff --git a/Min Cost Climbing Stairs.py b/Min Cost Climbing Stairs.py new file mode 100644 index 0000000..26b272f --- /dev/null +++ b/Min Cost Climbing Stairs.py @@ -0,0 +1,14 @@ +class Solution(object): + def minCostClimbingStairs(self, cost): + """ + :type cost: List[int] + :rtype: int + """ + f0,f1 = cost[0],cost[1] + for i in range(2,len(cost)): + tmp = cost[i] + min(f0,f1) + f0 = f1 + f1 = tmp + return min(f0,f1) + +