thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

LeetCode #62: Unique Paths

• 60 words • 1 min • updated

LeetCode #62: Unique Paths:

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)