본문 바로가기
Coding Test/LeetCode

[LeetCode] (Dynamic Programming) Lv Easy. Climbing Stairs

by song.ift 2023. 1. 22.

https://leetcode.com/explore/interview/card/top-interview-questions-easy/97/dynamic-programming/569/

 

Explore - LeetCode

LeetCode Explore is the best place for everyone to start practicing and learning on LeetCode. No matter if you are a beginner or a master, there are always new topics waiting for you to explore.

leetcode.com

 

javascript
닫기
/** * @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

 

GitHub - developeSHG/Algorithm-LeetCode: 릿코드 소스코드

릿코드 소스코드. Contribute to developeSHG/Algorithm-LeetCode development by creating an account on GitHub.

github.com

 

댓글