Post

leetcode(리트코드)6월07일 challenge746-Min Cost Climbing Stairs(python)

leetcode June 07일 - Min Cost Climbing Stairs 문제입니다.

1. 문제

https://leetcode.com/problems/min-cost-climbing-stairs/


2. Input , Output


3. 분류 및 난이도

Eazy 난이도입니다.
6월 07일자 챌린지 문제입니다.


4. 문제 해석

  • 비용(Cost)가 주어집니다.
  • 해당 칸에 도착했을 때 비용을 지불하고 계단을 1이나 2씩 오를 수 있습니다.
  • 위와 같은 방식으로 계단을 오를 때 최소환의 비용을 리턴하세요.

5. code

python

1
2
3
4
5
6
7
8
9
10
11
class Solution:
    def minCostClimbingStairs(self, cost: List[int]) -> int:
        cost.append(0)
        res = [0] * (len(cost))
        res[0] = cost[0]
        res[1] = cost[1]
        for i in range(2,len(cost)):
            res[i] = min(res[i-2] + cost[i], res[i-1] + cost[i])
        return res[len(res)-1]
        
        

6. 결과 및 후기, 개선점

필요시 c++로 풀어드립니다.

This post is licensed under CC BY 4.0 by the author.