leetcode_62_不同路径

题目

https://leetcode.cn/problems/unique-paths/description/?envType=study-plan-v2&envId=dynamic-programming

题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class Solution:
def uniquePaths(self, m: int, n: int) -> int:
# m行n列的矩阵
lst=[[0 for i in range(n)] for j in range(m)]

for i in range(m):
lst[i][0] = 1
for i in range(n):
lst[0][i] = 1

for i in range(1,m):
for j in range(1,n):
lst[i][j] = lst[i-1][j] + lst[i][j-1]

return lst[m-1][n-1]