File tree 2 files changed +29
-0
lines changed
2 files changed +29
-0
lines changed Original file line number Diff line number Diff line change 160
160
722|[ Remove Comments] ( ./0722-remove-comments.js ) |Medium|
161
161
733|[ Flood Fill] ( ./0733-flood-fill.js ) |Easy|
162
162
739|[ Daily Temperatures] ( ./0739-daily-temperatures.js ) |Medium|
163
+ 746|[ Min Cost Climbing Stairs] ( ./0746-min-cost-climbing-stairs.js ) |Easy|
163
164
762|[ Prime Number of Set Bits in Binary Representation] ( ./0762-prime-number-of-set-bits-in-binary-representation.js ) |Easy|
164
165
784|[ Letter Case Permutation] ( ./0784-letter-case-permutation.js ) |Medium|
165
166
791|[ Custom Sort String] ( ./0791-custom-sort-string.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 746. Min Cost Climbing Stairs
3
+ * https://leetcode.com/problems/min-cost-climbing-stairs/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are given an integer array cost where cost[i] is the cost of ith step on a staircase.
7
+ * Once you pay the cost, you can either climb one or two steps.
8
+ *
9
+ * You can either start from the step with index 0, or the step with index 1.
10
+ *
11
+ * Return the minimum cost to reach the top of the floor.
12
+ */
13
+
14
+ /**
15
+ * @param {number[] } cost
16
+ * @return {number }
17
+ */
18
+ var minCostClimbingStairs = function ( cost ) {
19
+ let [ first , second ] = cost ;
20
+
21
+ for ( let index = 2 ; index < cost . length ; index ++ ) {
22
+ const cursor = cost [ index ] + Math . min ( first , second ) ;
23
+ first = second ;
24
+ second = cursor ;
25
+ }
26
+
27
+ return Math . min ( first , second ) ;
28
+ } ;
You can’t perform that action at this time.
0 commit comments