当前位置:网站首页>Force buckle-746 Climb stairs with minimum cost

Force buckle-746 Climb stairs with minimum cost

2022-04-23 16:06:00 Node_ Su

I don't quite understand the topic , Standing on the 0 and 1 There is no need to spend ?

dp[i] Indicates reaching the current stair i The minimum cost of time

class Solution(object):
    def minCostClimbingStairs(self, cost):
        """
        :type cost: List[int]
        :rtype: int
        """
        n = len(cost)
        dp = [0] * (n + 1)
        for i in range(2, n + 1):
            dp[i] = min(cost[i - 1] + dp[i - 1], cost[i - 2] + dp[i - 2])
        return dp[n]


if __name__ == '__main__':
    cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
    Sol = Solution()
    res = Solution.minCostClimbingStairs(Sol, cost)
    print(res)

版权声明
本文为[Node_ Su]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231603458159.html