leetcode62Unique Paths

xiaoxiao2021-02-27  406

class Solution(object):     def uniquePaths(self, m, n):         """         :type m: int         :type n: int         :rtype: int         dp=[[1]*n for x in range(m)]         for i in range(1,m):             for j in range(1,n):                 dp[i][j]=dp[i-1][j]+dp[i][j-1]         return dp[-1][-1]         """         dp=[1]*m         for j in range(1,n):             for i in range(1,m):                 dp[i]+=dp[i-1]

        return dp[-1]

方法一:

和算最小和一样,先算行0和列0,相加

方法二:

先直接算向下走,走列次,一直摆到最后一个

转载请注明原文地址: https://www.6miu.com/read-3095.html

最新回复(0)