leetcode: 62. Unique Paths
来源:互联网 发布:mac pdf转word网页版 编辑:程序博客网 时间:2024/06/06 15:39
Q
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?
Note: m and n will be at most 100.
AC
class Solution(object): def uniquePaths(self, m, n): """ :type m: int :type n: int :rtype: int """ import math return math.factorial(m+n-2)/(math.factorial(m-1)*math.factorial(n-1))# Time: O(m * n)# Space: O(m + n)class Solution2(object): # @return an integer def uniquePaths(self, m, n): if m < n: return self.uniquePaths(n, m) ways = [1] * n for i in xrange(1, m): for j in xrange(1, n): ways[j] += ways[j - 1] return ways[n - 1]if __name__ == "__main__": assert Solution().uniquePaths(1, 2) == 1
阅读全文
0 0
- [LeetCode]62.Unique Paths
- LeetCode --- 62. Unique Paths
- LeetCode 62.Unique Paths
- [Leetcode] 62. Unique Paths
- [leetcode] 62.Unique Paths
- [leetcode] 62.Unique Paths
- leetcode 62. Unique Paths
- Leetcode 62. Unique Paths
- [leetcode] 62. Unique Paths
- 62. Unique Paths LeetCode
- [LeetCode]62. Unique Paths
- 【LeetCOde】62. Unique Paths
- [LeetCode]62. Unique Paths
- leetcode 62. Unique Paths
- LeetCode 62. Unique Paths
- LeetCode *** 62. Unique Paths
- leetcode 62. Unique Paths
- Leetcode:62. Unique Paths
- TensorFlow发布Eager,便于Debug!
- Android组件学习笔记(简单音乐播放器,service与intent)
- ADO 数据库编程
- Java核心技术-反射
- Java时间处理类SimpleDateFormat的parse和format
- leetcode: 62. Unique Paths
- window7下部署zookeeper、启动dubbo-admin
- leetcode: 63. Unique Paths II
- Shiro (五) Base64和Md5加密
- 201509-2 日期计算 ccf
- leetcode: 64. Minimum Path Sum
- Linux tree命令
- Aizu ALDS1_7_A Rooted Trees
- 如何解决未经处理的win32异常