36 ms 3-line Python solution


  • 1
    A
    import math
    class Solution(object):
    #    def __init__(self):
    #        self.map = {}
        def climbStairs(self, n):
            """
            :type n: int
            :rtype: int
            """
            p = (1+math.sqrt(5))/2.
            q = (1-math.sqrt(5))/2.
            return int( (p**(n+1) - q**(n+1)) / (p-q) )

  • 0
    D

    Nice solution, how did you find this formula?


  • 0
    A

    it's just the fibonacci number formula


Log in to reply
 

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