62. Unique Paths

来源:互联网 发布:网络维保服务模式 编辑:程序博客网 时间:2024/05/31 11:03

A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

How many possible unique paths are there?

经典动态规划:

class Solution:    def uniquePaths(self, m, n):        """        :type m: int        :type n: int        :rtype: int        """        dp=[[0]*n for i in range(m)]        for j in range(n):            dp[0][j]=1        for i in range(m):            dp[i][0]=1        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[m-1][n-1]


原创粉丝点击