Fast iterative python solution

  • 0
    class Solution(object):
        def climbStairs(self, n):
            :type n: int
            :rtype: int
            if n in {2, 1}:
                return n
            p = q = 1 
            for _ in xrange(2, n+1):
                p, q = q, p + q
            return q 

Log in to reply

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