LeetCode #62: Unique Paths
β’ 60 words β’ 1 min β’ updated
python
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
from functools import cache
@cache
def solve(m, n):
if m == 0 and n == 0:
return 1
if m < 0 or n < 0:
return 0
return solve(m - 1, n) + solve(m, n - 1)
return solve(m - 1, n - 1)