One Line Python


  • 0
    E

    f[n] contains the number of ways to climb n stairs:

    f[n] = f[n-1] + f[n-2] , n>=2

    It's obvious that f[1] = 1, f[2] = 2, so we assume that f[0] = 1, it's a fibbonacci array

    class Solution(object):
        def climbStairs(self, n):
            """
            :type n: int
            :rtype: int
            """
                
            return int((pow((1+math.sqrt(5))/2,n+1)-pow((1-math.sqrt(5))/2,n+1))/math.sqrt(5))

Log in to reply
 

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