LeetCode 63. Unique Paths II
来源:互联网 发布:云流量软件 编辑:程序博客网 时间:2024/05/17 06:10
描述
从左上走到右下右多少种走法,中间可能有障碍物
解决
动态规划,把存答案的数组初始化所有为0,然后从左到右,从上往下遍历下去即可
class Solution {public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { int r = obstacleGrid.size(); int c = r ? obstacleGrid[0].size() : 0; vector<vector<int>> res(r, vector<int>(c, 0)); res[0][0] = obstacleGrid[0][0] == 0 ? 1 : 0; for (int i = 0; i < r; ++i) { for (int j = 0; j < c; ++j) { if (i == 0 && j == 0) continue; if (obstacleGrid[i][j] != 1) { if (i == 0) { res[i][j] = res[i][j - 1]; } else if (j == 0) { res[i][j] = res[i - 1][j]; } else { res[i][j] = res[i - 1][j] + res[i][j - 1]; } } } } return res[r - 1][c - 1]; }};
0 0
- 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
- 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
- View及其子元素常用属性
- 异步任务
- NoteExpress使用中的一些问题
- eclipse 注释模版
- 用Python分解路径名的典型例子解说其实际操作
- LeetCode 63. Unique Paths II
- 联合概率与边缘概率
- time_t和字符串间的转化
- 数据结构期末总结
- 9错误处理
- 第15周 oj Problem I: 统计字符串种类
- 【CCF 模板生成系统 水】
- leetcode122
- 【每日一记】设计模式——外观模式