Here we can recognize fibbonacci sequence
recursievely
public class Solution {
public int ClimbStairs(int n) {
if (n == 0)
return 1;
return n > 1 ? ClimbStairs(n - 1) + ClimbStairs(n -2) : n;
}
}
iteratievely
public class Solution {
public int ClimbStairs(int n) {
if (n <= 1)
return 1;
int first = 1;
int second = 1;
for (int i = 2; i <= n; i++) {
int sum = first + second;
first = second;
second = sum;
}
return second;
}
}