Skip to content

Commit 22b0426

Browse files
Added Day-31 Solution
1 parent fab3f93 commit 22b0426

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

Day-31_Climbing_Staris.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
'''
2+
You are climbing a stair case. It takes n steps to reach to the top.
3+
4+
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
5+
6+
Example 1:
7+
8+
Input: 2
9+
Output: 2
10+
Explanation: There are two ways to climb to the top.
11+
1. 1 step + 1 step
12+
2. 2 steps
13+
Example 2:
14+
15+
Input: 3
16+
Output: 3
17+
Explanation: There are three ways to climb to the top.
18+
1. 1 step + 1 step + 1 step
19+
2. 1 step + 2 steps
20+
3. 2 steps + 1 step
21+
22+
23+
Constraints:
24+
25+
1 <= n <= 45
26+
Hide Hint #1
27+
To reach nth step, what could have been your previous steps? (Think about the step sizes)
28+
29+
'''
30+
31+
class Solution:
32+
def climbStairs(self, n: int) -> int:
33+
return round((0.5+sqrt(5)/2)**(n+1)/sqrt(5))
34+

0 commit comments

Comments
 (0)