32 ms Python solution


  • 0
    D
    class Solution(object):
        def climbStairs(self, n):
            """
            :type n: int
            :rtype: int
            """
            if n<3:
                return n
            else:
                first = 1
                second = 2 
                i = 3
                while i<n:
                    nsecond = first+second 
                    first = second
                    second = nsecond
                    i+=1
                return first+second

Log in to reply
 

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