Gary Lai
  • Home
  • About
Sign in Subscribe

746. Min Cost Climbing Stairs

Last updated on  Jan 5, 2024

746. Min Cost Climbing Stairs

class Solution:
    def minCostClimbingStairs(self, cost: List[int]) -> int:
        costs = [0] * (len(cost) + 1)
        costs[0] = cost[0]
        costs[1] = cost[1]
        cost.append(0)
        
        i = 2
        while i < len(costs):
            costs[i] = cost[i] + min(costs[i-1], costs[i-2])
            i += 1

        return costs[-1]
Previous Kth Smallest Element in a Sorted Matrix
Next 1137. N-th Tribonacci Number
Gary Lai © 2025
  • Sign up
Powered by Ghost