Skip to content

Commit 7be8452

Browse files
committed
Update method to use suffix helper on climbing stairs
1 parent b306f22 commit 7be8452

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
fun climbingStairsTopDown(n: Int): Int {
22
val memo = hashMapOf<Int, Int>()
3-
return climbingStairsTopDown(n, memo)
3+
return climbingStairsTopDownHelper(n, memo)
44
}
55

6-
fun climbingStairsTopDown(n: Int, memo: HashMap<Int, Int>): Int {
6+
fun climbingStairsTopDownHelper(n: Int, memo: HashMap<Int, Int>): Int {
77
// Base cases: With a 1-step staircase, there's only one way to
88
// climb it. With a 2-step staircase, there are two ways to climb it.
99
if (n <= 2) {
@@ -14,6 +14,6 @@ fun climbingStairsTopDown(n: Int, memo: HashMap<Int, Int>): Int {
1414
}
1515
// The number of ways to climb to the n-th step is equal to the sum
1616
// of the number of ways to climb to step n - 1 and to n - 2.
17-
memo[n] = climbingStairsTopDown(n - 1, memo) + climbingStairsTopDown(n - 2, memo)
17+
memo[n] = climbingStairsTopDownHelper(n - 1, memo) + climbingStairsTopDownHelper(n - 2, memo)
1818
return memo[n]!!
1919
}

0 commit comments

Comments
 (0)