We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 1465c63 commit 721db1dCopy full SHA for 721db1d
top-interview-questions/70. Climbing Stairs.cs
@@ -0,0 +1,30 @@
1
+public class Solution {
2
+ public int ClimbStairs(int n) {
3
+ if (n == 1) return 1;
4
+ if (n == 2) return 2;
5
+ int[] res = new int[n+1];
6
+ res[1] = 1;
7
+ res[2] = 2;
8
+ for (int i = 3; i <= n; i++) {
9
+ res[i] = res[i - 1] + res[i - 2];
10
+ }
11
+ return res[n];
12
13
+}
14
+
15
+// refactor to Fibonacci Number
16
17
18
+ if (n == 1) {
19
+ return 1;
20
21
+ int first = 1;
22
+ int second = 2;
23
24
+ int third = first + second;
25
+ first = second;
26
+ second = third;
27
28
+ return second;
29
30
0 commit comments