LEETCODE 62. Unique Paths LEETCODE 63. Unique Paths II
来源:互联网 发布:将表单数据转成json 编辑:程序博客网 时间:2024/05/22 04:36
题目大意
62题给出表格的大小,m是行数,n是列数,求从左上角到右下角可达路径的数量;63题在62题的基础上加上了obstacle的限制,需要处理的情况增加不少,需要注意。
62题原题
63题原题
代码
62题
class Solution {public: int uniquePaths(int m, int n) { const int rowSize = m; const int colSize = n; int statusTable[rowSize][colSize]; if (m <= 1 || n <= 1) { return 1; } for (int i = 0; i < rowSize; i++) { for (int j = 0; j < colSize; j++) { if (i == 0 || j == 0) { statusTable[i][j] = 1; } else { statusTable[i][j] = statusTable[i - 1][j] + statusTable[i][j - 1]; } } } return statusTable[rowSize - 1][colSize - 1]; }};
63题
class Solution {public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { if (obstacleGrid.size() < 1 || obstacleGrid[0].size() < 1) { return 1; } for (int i = 0; i < obstacleGrid.size(); i++) { for (int j = 0; j < obstacleGrid[i].size(); j++) { if (obstacleGrid[i][j] == 1) { obstacleGrid[i][j] = 0; } else if (i == 0 && j == 0) { obstacleGrid[i][j] = 1; }else if (i == 0) { obstacleGrid[i][j] = obstacleGrid[i][j - 1]; } else if (j == 0) { obstacleGrid[i][j] = obstacleGrid[i - 1][j]; } else { obstacleGrid[i][j] = obstacleGrid[i - 1][j] + obstacleGrid[i][j - 1]; } } } return obstacleGrid[obstacleGrid.size() - 1][obstacleGrid[0].size() - 1]; }};
0 0
- LEETCODE 62. Unique Paths LEETCODE 63. Unique Paths II
- LeetCode-62. Unique Paths/63. Unique Paths II
- [leetcode]62. Unique Paths/63. Unique Paths II -- JavaScript 代码
- Leetcode 62. Unique Paths和63. Unique Paths II
- Leetcode-62. Unique Paths and 63. Unique Paths II
- Leetcode 62. Unique Paths & 63. Unique Paths II
- LeetCode --- 63. Unique Paths II
- LeetCode 63.Unique Paths II
- [leetcode] 63.Unique Paths II
- [leetcode] 63.Unique Paths II
- Leetcode 63. Unique Paths II
- LeetCode 63. Unique Paths II
- [leetcode] 63. Unique Paths II
- leetcode 63. Unique Paths II
- 63. Unique Paths II LeetCode
- LeetCode 63. Unique Paths II
- [LeetCode]63. Unique Paths II
- leetcode 63. Unique Paths II
- 【计算机图形】画直线与画圆
- Php图片验证码显示不出来的解决过程
- numpy基本用法
- 51nod_1240 莫比乌斯函数
- 借助jsoup实现从网站页面中获取指定内容
- LEETCODE 62. Unique Paths LEETCODE 63. Unique Paths II
- 向量点积(Dot Product),向量叉积(Cross Product)
- UESTC CDOJ 1551 Hesty Str1ng 后缀数组+乱搞
- DEDECMS建站仿站使用的全局变量调用标签及路径大全整理总结
- HTTP Status 405
- 深入研究Java中一个对象的初始化过程
- 序列化异常 android.os.BadParcelableException
- Java获取Redis的日志信息和动态监控信息
- Spark源码学习笔记2-JobProgressListener