LeetCode - The World's Leading Online Programming Learning Platform
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(object):
def rob(self, nums):
"""
:type nums: List[int]
:rtype: int
"""
if not nums: return 0
prev1 = 0
prev2 = 0
for num in nums:
tmp = prev1
prev1 = max(prev2 + num, prev1)
prev2 = tmp
return prev1
LeetCode - The World's Leading Online Programming Learning Platform
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(object):
def minCostClimbingStairs(self, cost):
"""
:type cost: List[int]
:rtype: int
"""
step = [0] * len(cost)
total = 0
step[0] = cost[0]
step[1] = cost[1]
for i in range(2, len(cost)):
step[i] = min(step[i-1]+cost[i], step[i-2]+cost[i])
return min(step[len(cost)-1], step[len(cost)-2])
'공부용 > 모각코 개인' 카테고리의 다른 글
모각코 6주차 sql2 (0) | 2024.02.15 |
---|---|
모각코 5주차 sql1 (0) | 2024.02.04 |
모각코 3주차 순회문제 (0) | 2024.01.19 |
모각코 2주차 bfs (0) | 2024.01.14 |
모각코 1주차 dfs (0) | 2024.01.11 |