https://leetcode.com/explore/interview/card/top-interview-questions-easy/97/dynamic-programming/569/
/**
* @param {number} n
* @return {number}
*/
var climbStairs = function (n) {
const dp = new Map();
const Climbing = (n) => {
if ([1, 2].includes(n)) return n;
let n1 = parseInt(n - 1),
n2 = parseInt(n - 2);
if (!dp.has(n1)) dp.set(n1, Climbing(n1));
if (!dp.has(n2)) dp.set(n2, Climbing(n2));
return dp.get(n1) + dp.get(n2);
};
return Climbing(n);
};
GitHub : https://github.com/developeSHG/Algorithm-LeetCode/tree/main/climbing-stairs
'Coding Test > LeetCode' 카테고리의 다른 글
[LeetCode] (Design) Lv Easy. Shuffle an Array (0) | 2023.01.25 |
---|---|
[LeetCode] (Math) Lv Easy. Fizz Buzz (0) | 2023.01.22 |
[LeetCode] (Sorting and Searching) Lv Easy. First Bad Version (0) | 2023.01.22 |
[LeetCode] (Sorting and Searching) Lv Easy. Merge Sorted Array (0) | 2023.01.22 |
[LeetCode] (Trees) Lv Easy. Maximum Depth of Binary Tree (0) | 2023.01.21 |
댓글