// 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?

public class Solution {
    public int climbStairs(int n) {
        if(n == 0){
            return 1;
        }
        if(n == 1){
            return 2;
        }
        
        return climbStairs(n - 1) + climbStairs(n - 2);
    }
}

// more readable logic.
public class Solution {
    public int climbStairs(int n) {
        if (n <= 2) {
            return n;
        }
        int first = 1;
        int second = 2;
        int res = 0;
        n -= 2;
        
        while (n > 0) {
            res = second + first;
            first = second;
            second = res;
            n--;
        }
        
        return res;
    }
}
@@ -1,234 +1,264 @@
-// You are climbing a stair case. It takes n steps to reach to the top.%0A%0A// Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?%0A%0Apublic class Solution %7B%0A    public int climbStairs(int n
+public class Solution %7B%0A    public int climbStairs(int n) %7B%0A        if (n %25 2 == 0) %7B%0A            int%5B%5D temp = new int%5Bn + 1%5D;%0A            return recur(n, temp);%0A        %7D else %7B%0A            return iter(n);%0A        %7D%0A    %7D%0A    public int recur(int n, int%5B%5D buf
 ) %7B%0A
@@ -271,16 +271,18 @@
   if
+ 
 (n 
-== 0)
+%3C= 2) 
 %7B%0A  
@@ -298,17 +298,17 @@
  return 
-1
+n
 ;%0A      
@@ -325,16 +325,23 @@
   if
-(n == 1)
+ (buf%5Bn%5D != 0) 
 %7B%0A  
@@ -357,17 +357,22 @@
  return 
-2
+buf%5Bn%5D
 ;%0A      
@@ -396,112 +396,97 @@
     
-return climbStairs(n - 1) + climbStairs(n - 2
+buf%5Bn%5D = recur(n - 1, buf) + recur(n -2, buf
 );%0A
+%0A
     
-%7D%0A%7D%0A%0A// more readable logic.%0Apublic class Solution %7B
+    return buf%5Bn%5D;        %0A    %7D%0A    
 %0A   
@@ -493,35 +493,28 @@
  public int 
-climbStairs
+iter
 (int n) %7B%0A  
@@ -577,22 +577,80 @@
     
-int
+%0A        // third = first + second%0A        // ways to get to
  first 
-= 1;
+stair
 %0A   
@@ -662,18 +662,15 @@
 int 
-sec
 on
-d = 2
+e = 1
 ;%0A  
@@ -679,20 +679,39 @@
     
-int res = 0;
+// ways to get to second starit
 %0A   
@@ -715,19 +715,24 @@
         
-n -
+int two 
 = 2;%0A   
@@ -757,12 +757,15 @@
 e (n
- %3E 0
+-- != 2
 ) %7B%0A
@@ -780,28 +780,29 @@
     
+int th
 re
-s
+e
  = 
-sec
 on
-d + first
+e + two
 ;%0A  
@@ -815,65 +815,42 @@
     
-first = second;%0A            second = res;%0A            n--
+one = two;%0A            two = three
 ;%0A  
@@ -885,11 +885,11 @@
 urn 
-res
+two
 ;%0A  

update climbing stair solution