Anyone can solve the time limit exceeded problem?


  • 0
    E

    I wrote like this. But after I submitted, it shows Time Limit Exceeded when n == 44.
    Anyone can help me figure out why this happened?

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

Log in to reply
 

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