My 6 lines Python solution


  • 0
    C
    class Solution(object):
    def climbStairs(self, n):
        """
        :type n: int
        :rtype: int
        """
        l = [1,2]
        if n < 3:
            return n
        for i in range(n-2):
            l[i%2] = l[0]+l[1]
        return max(l)

  • 0
    X
    class Solution(object):
    def climbStairs(self, n):
        """
        :type n: int
        :rtype: int
        """
        last ,now = 1 ,1
        for i in xrange(n-1):now ,last = last+now ,now
        return now
    

    #look my 3 line solution


Log in to reply
 

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