[Python手撕]使用最小花費爬樓梯

Duancf發表於2024-10-04
class Solution:
    def minCostClimbingStairs(self, cost: List[int]) -> int:

        dp = cost
        n = len(dp)
        for i in range(2,n):
            dp[i] += min(dp[i-1],dp[i-2])
        return min(dp[-1],dp[-2])

相關文章