题解 | #最小花费爬楼梯#
最小花费爬楼梯
http://www.nowcoder.com/practice/6fe0302a058a4e4a834ee44af88435c7
#coding:utf-8
#
# 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可
#
#
# @param cost int整型一维数组
# @return int整型
#
class Solution:
def minCostClimbingStairs(self , cost ):
# write code here
if not cost or len(cost)<2:
return 0
cost.append(0)
a,b = 0,0
for i in range(2,len(cost)):
c = min(a+cost[i-2],b+cost[i-1])
a,b = b,c
return c