leetcode-746. 使用最小花费爬楼梯

题目

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)];
    }

posted @ 2022-01-03 21:31  吴丹阳-V  阅读(24)  评论(0编辑  收藏  举报