From 6007c97cc2c67ca8a7eac12446e175aa145db2f9 Mon Sep 17 00:00:00 2001 From: BangDori Date: Mon, 16 Dec 2024 23:59:54 +0900 Subject: [PATCH] Climbing Stairs --- bangdori/Climbing Stairs.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 bangdori/Climbing Stairs.js diff --git a/bangdori/Climbing Stairs.js b/bangdori/Climbing Stairs.js new file mode 100644 index 0000000..b12f965 --- /dev/null +++ b/bangdori/Climbing Stairs.js @@ -0,0 +1,15 @@ +/** + * @param {number} n + * @return {number} + */ +var climbStairs = function (n) { + const dp = Array.from(n, () => 0); + dp[0] = 1; + dp[1] = 1; + + for (let i = 2; i <= n; i++) { + dp[i] = dp[i - 1] + dp[i - 2]; + } + + return dp[n]; +};