Advertisement
gelita

climb stairs 1 or 2 stairs (pure recursion)

Feb 15th, 2020
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.30 KB | None | 0 0
  1. class Solution {
  2.     public int climbStairs(int n) {
  3.         if(n < 0){
  4.             return 0;
  5.         }
  6.         if(n == 0 || n == 1){
  7.             return 1;
  8.         }
  9.         if(n == 2){
  10.             return 2;// 1+1 & 2
  11.         }
  12.         return climbStairs(n-2) + climbStairs(n-1);
  13.     }
  14.    
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement