63 leetcode - Unique Paths
2016-12-27 20:41
375 查看
#!/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 == 0 or n == 0: return 0 dp = [[0] * n for i in range(m)] for i in range(n): dp[0][i] = 1 for i in range(m): dp[i][0] = 1 for row in range(1,m): for col in range(1,n): dp[row][col] = dp[row - 1][col] + dp[row][col - 1] return dp[m-1][n-1] if __name__ == "__main__": s = Solution() print s.uniquePaths(2,2)
相关文章推荐
- LeetCode-62&63.Unique Paths
- Leetcode62-63 Unique Paths
- 【Leetcode】Unique Paths
- LeetCode 62. Unique Paths
- LeetCode(62): Unique Paths
- [leetcode]Unique Paths
- leetcode - Unique Paths
- 【LeetCode-面试算法经典-Java实现】【062-Unique Paths(唯一路径)】
- LeetCode(63)-First Bad Version
- Leetcode 63 Unique Paths II
- Leetcode:Unique Paths
- leetcode: Unique Paths
- leetcode_Unique Paths
- [Leetcode 58] 63 Unique Path II
- leetCode练习(63)
- [LeetCode] Unique Paths 2
- 【LeetCode】(63)Unique Paths II(Medium)
- LeetCode | Unique Paths
- LeetCode 62 --- Unique Paths
- LeetCode 62 Unique Paths