
g0001_0100.s0070_climbing_stairs.solution.ts Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of leetcode-in-all Show documentation
Show all versions of leetcode-in-all Show documentation
104 LeetCode algorithm problem solutions
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #Dynamic_Programming #Math #Memoization
// #Algorithm_I_Day_12_Dynamic_Programming #Dynamic_Programming_I_Day_2
// #Level_1_Day_10_Dynamic_Programming #Udemy_Dynamic_Programming #Big_O_Time_O(n)_Space_O(n)
// #2023_10_01_Time_44_ms_(94.58%)_Space_42.4_MB_(73.09%)
function climbStairs(n: number, memo: Record = {}): number {
if (n in memo) return memo[n]
if (n === 0) return 1
if (n < 0) return 0
memo[n] = climbStairs(n - 1, memo) + climbStairs(n - 2, memo)
return memo[n]
}
export { climbStairs }
© 2015 - 2025 Weber Informatics LLC | Privacy Policy