From 44c365a7baea23877053bb7966bcaaf6c81c1de8 Mon Sep 17 00:00:00 2001 From: xiaoyu2018 <861900161@qq.com> Date: Sun, 25 Sep 2022 16:13:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A00746=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E6=9C=80=E5=B0=8F=E8=8A=B1=E8=B4=B9=E7=88=AC=E6=A5=BC=E6=A2=AF?= =?UTF-8?q?C#=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0746.使用最小花费爬楼梯.md | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/problems/0746.使用最小花费爬楼梯.md b/problems/0746.使用最小花费爬楼梯.md index 9d3bd7fa..4a4c0b65 100644 --- a/problems/0746.使用最小花费爬楼梯.md +++ b/problems/0746.使用最小花费爬楼梯.md @@ -370,5 +370,26 @@ object Solution { } ``` +### C# + +```c# +public class Solution +{ + public int MinCostClimbingStairs(int[] cost) + { + int[] dp=new int[2] { cost[0], cost[1] }; + for (int i = 2; i < cost.Length; i++) + { + int temp = Math.Min(dp[0], dp[1])+cost[i]; + dp[0]=dp[1]; + dp[1]=temp; + } + return Math.Min(dp[0],dp[1]); + } +} +``` + + + -----------------------