class Solution { public int fib(int n) { if(n==0){ return 0; }else if(n==1 || n==2){ return 1; }else{ return fib(n-1)+fib(n-2); } } } class Solution { public int fib(int n) { if(n==0){ return 0; }else if(n==1 || n==2){ return 1; }else{ int dp[] = new int[n+1]; dp[0] = 0; dp[1] = 1; dp[2] = 1; for(int i=3;i<=n;i++){ dp[i] = dp[i-1]+dp[i-2]; } return dp[n]; } } } class Solution { public int fib(int n) { if(n==0){ return 0; }else if(n==1 || n==2){ return 1; }else{ int steps1 = 1; int steps2 = 1; int sum = 0; for(int i=3;i<=n;i++){ sum = steps1 + steps2; steps1 = steps2; steps2 = sum; } return sum; } } }