diff --git a/2021-08/2021-08-26 (day39)/Kevin/README.md b/2021-08/2021-08-26 (day39)/Kevin/README.md new file mode 100644 index 00000000..10850378 --- /dev/null +++ b/2021-08/2021-08-26 (day39)/Kevin/README.md @@ -0,0 +1 @@ +# Climbing Stairs \ No newline at end of file diff --git a/2021-08/2021-08-26 (day39)/Kevin/solution.js b/2021-08/2021-08-26 (day39)/Kevin/solution.js new file mode 100644 index 00000000..5baacba1 --- /dev/null +++ b/2021-08/2021-08-26 (day39)/Kevin/solution.js @@ -0,0 +1,17 @@ +/** + * @param {number} n + * @return {number} + */ + var climbStairs = function(n) { + return helper(n, []) +}; + +function helper(n, cache){ + if(cache[n]){ + return cache[n] + } + if(n === 1) cache[n] = 1 + else if(n === 2) cache[n] = 2 + else cache[n] = helper(n-2, cache) + helper(n-1, cache) + return cache[n] +} \ No newline at end of file