You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
Idea: This is Fibonacci sequence that F(N)=F(N-1)+F(N-2)
public class Solution {
public int climbStairs(int n) {
int F1=1;
int F2=2;
int F3=0;
if(n==1) return F1;
if(n==2) return F2;
for(int i=3; i<=n;i++){
F3=F1+F2;
F1=F2;
F2=F3;
}
return F3;
}
}