-
Notifications
You must be signed in to change notification settings - Fork 229
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #617 from CSAURABH/issue-#494
Created Climbing Stairs on Leetcode
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
MORE CODING PLATFORMS/LeetCode/Climbing Stairs/Solution.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
}; |