39ms in Python


  • 0
    C

    '''
    class Solution(object):
    def climbStairs(self, n):

        if n <= 1: return 1
        # previous and current
        pre = 1
        cur = 1
        # fibonacci f(n) = f(n-1) + f(n-2)
        for i in range(2,n+1): 
            temp = cur
            cur = cur + pre
            pre = temp
        return cur
    

    '''


Log in to reply
 

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