Time Complexity: O(n)
Space Complexity: O(1)
class Solution:
def climbStairs(self, n: int) -> int:
prev, pprev = 2, 1
if n == 1:
return 1
if n == 2:
return 2
res = 0
for i in range(2, n):
res = prev + pprev
pprev, prev = prev, res
return res