leetcode unique paths ii
来源:互联网 发布:硕鼠一样的软件 编辑:程序博客网 时间:2024/05/23 19:16
class Solution {public: int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { int h = obstacleGrid.size(); if(h == 0){ return 0; } int w = obstacleGrid[0].size(); if(w == 0){ return 0; } vector<int>dp; dp.resize(w, 0); dp[0] = obstacleGrid[0][0] == 1 ? 0: 1; if(dp[0] == 0){ return 0; } for(int i = 1; i < w; ++i){ dp[i] = obstacleGrid[0][i] == 1 ? 0: (dp[i - 1]); } for(int i = 1; i < h; ++i){ dp[0] = (dp[0] == 0 || obstacleGrid[i][0] == 1) ? 0 : 1; for(int j = 1; j < w; ++j){ dp[j] = obstacleGrid[i][j] == 1 ? 0: (dp[j] + dp[j-1]); } } return dp[w - 1]; }};
错误1:
1. 矩阵的行和列傻傻分不清楚..下标写错..runtime error
2. 初始化dp[0]时忘记了前面的obstacle对后面的影响
0 0
- LeetCode: Unique Paths II
- [Leetcode] Unique Paths II
- LeetCode : Unique Paths II
- [LeetCode] Unique Paths II
- [LeetCode]Unique Paths II
- [leetcode]Unique Paths II
- LeetCode-Unique Paths II
- [leetcode] Unique Paths II
- LeetCode - Unique Paths II
- LeetCode:Unique Paths II
- 【LeetCode】Unique Paths II
- leetcode Unique Paths II
- LeetCode Unique Paths II
- LeetCode | Unique Paths II
- Leetcode: Unique Paths II
- LeetCode Unique Paths II
- Unique Paths II -- LeetCode
- [LeetCode] Unique Paths II
- 数据库调优教程(七)索引的代价
- 【Android开发】android-AsyncTask介绍
- 金山词霸在360极速浏览器下不能取词
- Cascade Opencv -- train new model
- Linux Netlink通信机制详解(下)
- leetcode unique paths ii
- java.sql.SQLException: 无效的列索引: getValidColumnIndex
- 从网上获取一个网页,在一个TextView中将其源代码显示出来
- 杭电ACM 1003:Max Sum
- xUtils 源码解析
- Qt使用总结
- Java 获取文件夹里文件的名字
- asp.net上传文件重命名的方法及IO修改文件名
- ViewPagerindicator 源码解析