天天看點

63 leetcode - Unique Paths

63 leetcode - Unique Paths
#!/usr/bin/python
# -*- coding: utf-8 -*-
'''
Unique Paths
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(object):
    def uniquePaths(self, m, n):
        """
        :type m: int
        :type n: int
        :rtype: int
        """
        if m ==  or n == :
            return 

        dp = [[] * n  for i in range(m)]
        for i in range(n):
            dp[][i] = 
        for i in range(m):
            dp[i][] = 

        for row in range(,m):
            for col in range(,n):
                dp[row][col] = dp[row - ][col] + dp[row][col - ]

        return dp[m-][n-]

if __name__ == "__main__":
    s = Solution()
    print s.uniquePaths(,)