File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments