Simple python O(n) with O(1) space

  • 0
    class Solution(object):
        def climbStairs(self, n):
            if n < 3:
                return n
            a, b = 1, 1
            for i in range(n-1):
                c = b 
                b = a + b
                a = c
            return b

Log in to reply

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