Created
August 18, 2023 07:35
-
-
Save henokkhm/658fd4f9441e8c24f66f7a8cdd30b941 to your computer and use it in GitHub Desktop.
LeetCode Climb Stairs [18 Aug 2023 Mob Programming]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * 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