From 088d4638df1c84a68f77dc052b9278307e31aa3d Mon Sep 17 00:00:00 2001 From: Yaseen Khan <78000116+Ykhan799@users.noreply.github.com> Date: Wed, 31 Aug 2022 14:52:06 -0700 Subject: [PATCH] Create: 746-Min-Cost-Climbing-Stairs.swift --- swift/746-Min-Cost-Climbing-Stairs.swift | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 swift/746-Min-Cost-Climbing-Stairs.swift diff --git a/swift/746-Min-Cost-Climbing-Stairs.swift b/swift/746-Min-Cost-Climbing-Stairs.swift new file mode 100644 index 000000000..aebcf960a --- /dev/null +++ b/swift/746-Min-Cost-Climbing-Stairs.swift @@ -0,0 +1,9 @@ +class Solution { + func minCostClimbingStairs(_ cost: [Int]) -> Int { + var stepsCost = cost + for i in stride(from: cost.count - 3, through: 0, by: -1) { + stepsCost[i] += min(stepsCost[i + 1], stepsCost[i + 2]) + } + return min(stepsCost[0], stepsCost[1]) + } +} \ No newline at end of file