Skip to content

Instantly share code, notes, and snippets.

@henokkhm
Created August 18, 2023 07:35
Show Gist options
  • Select an option

  • Save henokkhm/658fd4f9441e8c24f66f7a8cdd30b941 to your computer and use it in GitHub Desktop.

Select an option

Save henokkhm/658fd4f9441e8c24f66f7a8cdd30b941 to your computer and use it in GitHub Desktop.
LeetCode Climb Stairs [18 Aug 2023 Mob Programming]
/**
* Link to problem
* https://leetcode.com/problems/climbing-stairs/submissions/
*/
/**
* @param {number} n
* @return {number}
*/
const memo = new Map();
var climbStairs = function (n) {
const memoizedValue = memo.get(n);
if (memoizedValue) { return memoizedValue; }
if (n === 1) { return 1; }
if (n === 2) { return 2; }
const result = climbStairs(n - 1) + climbStairs(n - 2);
memo.set(n, result);
return result;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment