62. Unique Paths - LeetCode
import math
class Solution1:
def uniquePaths(self, m: int, n: int) -> int:
return math.comb((m - 1) + (n - 1), (n - 1))
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
dp = [1] + [0 for _ in range(n - 1)]
for _ in range(m):
for i in range(n - 1):
dp[i + 1] += dp[i]
return dp[n - 1]