# Leetcode 746. Min Cost Climbing Stairs ###### tags: `Leetcode(C++)` 題目 : https://leetcode.com/problems/min-cost-climbing-stairs/ 。 想法 : 陣列代表的狀態 : 走到這一階中最少的COST,每一階都是由前一階 or 前二階走來的。 時間複雜度 : O(n)。 程式碼 : ``` class Solution { public: int minCostClimbingStairs(vector<int>& cost) { int ans[1010]={0},l=cost.size(); for(int i=2 ; i<=l ; i++){ cout << ans[i-2] << " " << ans[i-1] << "\n"; ans[i]=min(ans[i-2]+cost[i-2],ans[i-1]+cost[i-1]); cout << ans[i] << "\n"; } return ans[l]; } }; ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up