<filename>leetcode/unique_paths.py<gh_stars>0
# https://leetcode.com/problems/unique-paths/


class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        if m == 1 or n == 1:
            return 1
        return self.uniquePaths(m - 1, n) + self.uniquePaths(m, n - 1)

    def uniquePathsV2(self, m: int, n: int) -> int:
        row = [1] * n
        for index_m in range(1, m):
            for index_n in range(1, n):
                row[index_n] += row[index_n - 1]
        return row[n - 1]


print(Solution().uniquePathsV2(3, 7))
print(Solution().uniquePathsV2(3, 2))
print(Solution().uniquePathsV2(7, 3))
print(Solution().uniquePathsV2(3, 3))
<filename>leetcode/unique_paths.py<gh_stars>0
# https://leetcode.com/problems/unique-paths/


class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        if m == 1 or n == 1:
            return 1
        return self.uniquePaths(m - 1, n) + self.uniquePaths(m, n - 1)

    def uniquePathsV2(self, m: int, n: int) -> int:
        row = [1] * n
        for index_m in range(1, m):
            for index_n in range(1, n):
                row[index_n] += row[index_n - 1]
        return row[n - 1]


print(Solution().uniquePathsV2(3, 7))
print(Solution().uniquePathsV2(3, 2))
print(Solution().uniquePathsV2(7, 3))
print(Solution().uniquePathsV2(3, 3))
# https://leetcode.com/problems/unique-paths/