[
math
dp
matrix power
]
BinarySearch 0010 A Flight of Stairs
Problem statement
https://binarysearch.com/problems/A-Flight-of-Stairs/
Solution
Almost the same as leetcode Leetcode 0070. Climbing Stairs
Complexity
It is O(n)
for time and O(1)
for space.
Code
class Solution:
def solve(self, n):
dp, M = (1, 1), 10**9 + 7
for i in range(n-1):
dp = (dp[1] % M, (dp[0] + dp[1]) % M)
return dp[1]