Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- Top-down
- Programmers
- golang
- 그리디
- Backjoon
- GCP
- LeetCode
- docker
- k8s
- BubbleSort
- Kotlin
- Python
- KAKAO
- GKE
- go
- 피보나치
- github
- Singleton Pattern
- kubernetes
- cpu scheduling
- 파이썬
- Dynamic Programming
- java
- Observer Pattern
- 알고리즘
- Codility
- mobaXTerm
- 백준
- easy
Archives
- Today
- Total
To Be Developer
[LeetCode] 746. Min Cost Climbing (Python) 본문
https://leetcode.com/problems/min-cost-climbing-stairs/
class Solution(object):
def minCostClimbingStairs(self, cost):
size = len(cost) # cost size
dp = [cost[0] if i==0 else cost[1] if i==1 else 0 for i in range(size)] # 컴프리헨션을 하면서 i가 0, 1 일 때 초기화
for i in range(2, size): dp[i] = cost[i] + min(dp[i-1], dp[i-2]) # dp[i] = cost[i] + min(dp[i-1]+dp[i-2])
return min(dp[size-2], dp[size-3]+cost[i]) # 지역변수 i 가 살아있음 신기..
sl = Solution().minCostClimbingStairs([1, 100, 1,1,1,100,1,1,100,1])
print(sl)
'알고리즘 > LeetCode' 카테고리의 다른 글
[LeetCode] 27. Remove Element(Python, GoLang) (0) | 2019.04.29 |
---|---|
[LeetCode] 219. Contains Duplicate II (Python) (0) | 2019.04.22 |
[LeetCode] 504. Relative Ranks (Python) (0) | 2019.04.21 |
[LeetCode] 20. Valid Parentheses (Python) (0) | 2019.04.17 |
[LeetCode] 62. Unique Paths (GoLang, Python) (0) | 2019.04.12 |