ByteByteGo: Matrix Pathways
β’ 67 words β’ 1 min β’ updated
python
def matrix_pathways(m: int, n: int) -> int:
from functools import lru_cache
@lru_cache(maxsize=None)
def solve(m, n):
# from 1 to m, from 1 to n
assert (m, n) >= (0, 0)
if m == 0 or n == 0:
return 0
if m == 1 and n == 1:
return 1
return solve(m - 1, n) + solve(m, n - 1)
return solve(m, n)