Time limit exceeded?


  • 0
    Y

    I use recursion in Java. When n is less than 2 just return the n
    When n gets larger, it becomes a fabonacci number
    but every time I submit it says time limit exceeded


  • 0
    L

    It is better to solve this problem using DP, If you do want to use recursion, you may can use a buffer to record the stairs you have counted to avoid do the same recursive call again.
    If you did not get what I am saying, just google "fibonacci series dynamic programming ".


  • 0
    L

    we think the same.


Log in to reply
 

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