1 class Solution: 2 def uniquePaths(self, m: int, n: int) -> int: 3 # 创建一个二维列表用于存储唯一路径数 4 dp = [[0] * n for _ in range(m)] 5 6 # 设置第一行和第一列的基本情况 7 for i in range(m): 8 dp[i][0] = 1 9 for j in range(n): 10 dp[0][j] = 1 11 12 # 计算每个单元格的唯一路径数 13 for i in range(1, m): 14 for j in range(1, n): 15 dp[i][j] = dp[i - 1][j] + dp[i][j - 1] 16 17 # 返回右下角单元格的唯一路径数 18 return dp[m - 1][n - 1]
标签:int,训练营,路径,随想录,62,range,dp From: https://www.cnblogs.com/wuyijia/p/17725761.html