Three Lines Java Solution Recursion


  • 0
    J

    // There is a time limit exceed error after climbing 40 steps

    public class Solution {

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

    }


  • 0
    Z
    This post is deleted!

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.