Python 4 lines O(1) space


  • 1
    N

    Just need to compute n+1'th fibonacci number.

        def climbStairs(self, n):
            l1, l2 = 0, 1
            for _ in range(n):
                l1, l2 = l2, l1 + l2
            return l2
    

Log in to reply
 

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