Exceed Time Limit

  • 0

    It says my running time exceeds. Does it mean that recursion is not accepted in Python?

    class Solution:
    # @param {integer} n
    # @return {integer}
    def climbStairs(self, n):
        Total = 0
        if n == 1:
            Total = 1
        elif n == 2:
            Total = 2
            Total = self.climbStairs(n-1) + self.climbStairs(n-2)
        return Total

  • 0

    You need to cache the result of each recursion. e.g. Store them in a array.

Log in to reply

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