Skip to content
This repository was archived by the owner on Oct 4, 2022. It is now read-only.

Climb Stairs | DP #2099

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions C++/Algorithms/Dynamic Programming/kc.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@



// Name - 70
// Dificulty - Easy
// Problem number - 70
// Link -https://leetcode.com/problems/climbing-stairs/

class Solution {
public:
int solve(int n , vector<int> &dp)
{
if(n==0) return 0;
if(n==1) return 1;
if(n==2) return 2;

if(dp[n]!=-1) return dp[n];

return dp[n] = solve(n-1,dp) + solve(n-2,dp);
}
int climbStairs(int n) {
vector<int> dp(n+1,-1);
return solve(n,dp);
}