File tree 2 files changed +27
-0
lines changed
2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change 53
53
58|[ Length of Last Word] ( ./0058-length-of-last-word.js ) |Easy|
54
54
66|[ Plus One] ( ./0066-plus-one.js ) |Easy|
55
55
67|[ Add Binary] ( ./0067-add-binary.js ) |Easy|
56
+ 70|[ Climbing Stairs] ( ./0070-climbing-stairs.js ) |Easy|
56
57
73|[ Set Matrix Zeroes] ( ./0073-set-matrix-zeroes.js ) |Medium|
57
58
74|[ Search a 2D Matrix] ( ./0074-search-a-2d-matrix.js ) |Medium|
58
59
77|[ Combinations] ( ./0077-combinations.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 70. Climbing Stairs
3
+ * https://leetcode.com/problems/climbing-stairs/
4
+ * Difficulty: Easy
5
+ *
6
+ * You are climbing a staircase. It takes n steps to reach the top.
7
+ *
8
+ * Each time you can either climb 1 or 2 steps. In how many distinct
9
+ * ways can you climb to the top?
10
+ */
11
+
12
+ /**
13
+ * @param {number } n
14
+ * @return {number }
15
+ */
16
+ var climbStairs = function ( n ) {
17
+ const cache = new Map ( ) ;
18
+ const memo = n => {
19
+ if ( n < 4 ) return n ;
20
+ if ( ! cache . has ( n ) ) {
21
+ cache . set ( n , memo ( n - 2 ) + memo ( n - 1 ) ) ;
22
+ }
23
+ return cache . get ( n ) ;
24
+ } ;
25
+ return memo ( n ) ;
26
+ } ;
You can’t perform that action at this time.
0 commit comments