62. Unique Paths
来源:互联网 发布:django 生鲜教程源码 编辑:程序博客网 时间:2024/05/18 09:38
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?
Above is a 3 x 7 grid. How many possible unique paths are there?
Note: m and n will be at most 100.
java
class Solution { public int uniquePaths(int m, int n) { int[][] f = new int[m][n]; for (int i = 0; i < m; i++) { f[i][0] = 1; } for (int j = 0; j < n; j++) { f[0][j] = 1; } for (int i = 1; i < m; i++) { for (int j = 1; j < n; j++) { f[i][j] = f[i - 1][j] + f[i][j - 1]; } } return f[m - 1][n - 1]; }}
python
class Solution: """ @param: m: positive integer (1 <= m <= 100) @param: n: positive integer (1 <= n <= 100) @return: An integer """ def uniquePaths(self, m, n): # write your code here res = [[1] * n] * m for i in range(1, m): for j in range(1, n): res[i][j] = res[i - 1][j] + res[i][j - 1] return res[m - 1][n - 1]
阅读全文
0 0
- 62. Unique Paths && 63. Unique Paths II
- 62. Unique Paths \ 63. Unique Paths II
- [LeetCode]62.Unique Paths
- LeetCode --- 62. Unique Paths
- LeetCode 62.Unique Paths
- [Leetcode] 62. Unique Paths
- [leetcode] 62.Unique Paths
- 62. Unique Paths
- [leetcode] 62.Unique Paths
- leetcode 62. Unique Paths
- Leetcode 62. Unique Paths
- [leetcode] 62. Unique Paths
- 62. Unique Paths LeetCode
- 62. Unique Paths
- 62. Unique Paths
- [LeetCode]62. Unique Paths
- 【LeetCOde】62. Unique Paths
- [LeetCode]62. Unique Paths
- Divided Land(一道gcd的题)
- linux用户和用户组
- python取时间,推荐用datetime
- 友元函数与只读函数
- 求解方程根的近似解:弦截法
- 62. Unique Paths
- nginx+php在 window下 自动退出 php-cgi解决方案
- 编写一个学生类(Students),包括姓名(name)、性别(sex)、学号(num)、语文课(Chinese)、英语课(English)、 数学课(Math)和平均值(avg),方法包括求
- 菜鸟学框架——JDBC VS Hibernate VS Mybatis
- HTML简单标签
- netty源码分析(十四)Netty初始化流程总结及Channel与ChannelHandlerContext作用域分析
- sql优化技巧
- 任重而道远
- RedHat6.5安装MySQL5.7