62. Unique Paths
来源:互联网 发布:迅龙恢复软件注册码 编辑:程序博客网 时间:2024/06/08 06:59
class Solution {public: int uniquePaths(int m, int n) { //自底向上,从最后一个节点的方案数向回计算 int a[1000][1000]; if(n ==1 || m==1){ return 1; } a[m][n] = 1; for(int i = m ; i >=1 ;i-- ){ for(int j = n ; j >=1;j--){ if( i==m || j==n){ //一旦一条边已经达到边缘,方案数目就没有变化了 a[i][j] =1; } else{ a[i][j] = a[i][j+1] +a[i+1][j]; } } } return a[1][1]; }};
class Solution {public: //第二种从正向开始 int uniquePaths(int m, int n) { int a[m][n]; for(int i = 0; i < m; i++){ a[i][0] = 1; } for(int i = 0; i < n; i++){ a[0][i] = 1; } for(int i=1;i<m;i++){ for(int j=1;j<n;j++){ a[i][j] = a[i-1][j]+a[i][j-1]; } } return a[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
- 数独问题
- 分化数小数
- Doze模式调试下AlarmManager后台运行问题
- java基础知识
- Java 抽象类、普通类、接口的区别——值得你一看的干货
- 62. Unique Paths
- 呼叫中心开发框架Asterisk
- Longest Palindromic Substring
- SSH和SSM对比总结
- python:序列
- 解决“ipheth_tx_timeout: TX timeout”
- python杂记
- jmeter插件之自定义场景图(万能场景设计)
- 什么是启发式算法(heuristic algorithm)?