leetcode746. 使用最小花费爬楼梯 吴丹阳

题目

746. 使用最小花费爬楼梯

解法

\[fn= \left\{ \begin{array}{**lr**} min(f_{n-1}, f_{n-2})\ +\ n, & n\geq 3 \\ n, & n=0|n=1 & \\ \end{array} \right. \]

class Solution {
    
    /**
     * @param Integer[] $cost
     * @return Integer
     */
    function minCostClimbingStairs($cost) {
        $ret = [$cost[0], $cost[1]];
    
        for ($i = 2; $i <= count($cost); $i++) {
            $ret[$i] = min($ret[$i-1], $ret[$i-2]) + $cost[$i];
        }
        
        return $ret[count($cost)];
    }

本文来自博客园,作者:吴丹阳-cn,转载请注明原文链接:https://www.cnblogs.com/wudanyang/p/15760597.html

原文地址:https://www.cnblogs.com/wudanyang/p/15760597.html