Skip to content

Commit

Permalink
Merge pull request #617 from CSAURABH/issue-#494
Browse files Browse the repository at this point in the history
Created Climbing Stairs on Leetcode
  • Loading branch information
hhhrrrttt222111 authored Oct 4, 2021
2 parents 1be5212 + a4d5e5a commit dd41d0b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
28 changes: 28 additions & 0 deletions MORE CODING PLATFORMS/LeetCode/Climbing Stairs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# [Climbing Stairs](https://leetcode.com/problems/climbing-stairs/)

## Question :-

You are climbing a staircase. It takes n steps to reach the top.

Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?

### Example 1:

Input: n = 2

Output: 2

Explanation: There are two ways to climb to the top.
1. 1 step + 1 step
2. 2 steps

### Example 2:

Input: n = 3

Output: 3

Explanation: There are three ways to climb to the top.
1. 1 step + 1 step + 1 step
2. 1 step + 2 steps
3. 2 steps + 1 step
16 changes: 16 additions & 0 deletions MORE CODING PLATFORMS/LeetCode/Climbing Stairs/Solution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Solution {
public:
int climbStairs(int n) {

int dp[n+1];

dp[0] = 1;
dp[1] = 1;

for(int i = 2; i <= n; i++)
{
dp[i] = dp[i - 1] + dp[i - 2];
}
return dp[n];
}
};

0 comments on commit dd41d0b

Please sign in to comment.