https://leetcode.com/problems/min-cost-climbing-stairs/
Min Cost Climbing Stairs - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
계단문제의 변형입니다.
가장 적은 걸음수로 계단을 오르는 유형과 흡사한 가장 적은 힘을 들이고 계단을 오르는 값을 찾는 문제입니다.
각 계단별로 여기까지 오는데 쓰는 최소한의 힘을 기억시키고 규칙에 따라 하나씩 최솟값을 채워가며 구현했습니다.
class Solution:
def minCostClimbingStairs(self, cost: list) -> int:
size = len(cost) + 1
dp = [0] * size
for i in range(2,size):
dp[i] = min((dp[i-1] + cost[i-1]),(dp[i-2] + cost[i-2]))
return dp[-1]
input = [[10,15,20],[1,100,1,1,1,100,1,1,100,1]]
for i in input:
print(Solution().minCostClimbingStairs(i))
728x90
'🔍 알고리즘 > Leetcode' 카테고리의 다른 글
[Python] Leetcode 206. Reverse Linked List (Easy) (0) | 2022.07.23 |
---|---|
[Python] Leetcode 21. Merge Two Sorted Lists (Easy) (0) | 2022.07.23 |
[Python] Leetcode 70. Climbing Stairs (Easy) (0) | 2022.07.22 |
[Python] Leetcode 1137. N-th Tribonacci Number(Easy) (0) | 2022.07.22 |
[Python] Leetcode 509. Fibonacci Number (Easy) (0) | 2022.07.22 |