Leetcode Unique Paths II
来源:互联网 发布:player for mac 编辑:程序博客网 时间:2024/06/07 18:36
题意:Unique Path的衍生题,加入了障碍物。
思路:DP,将障碍物的dp值置为0。
class Solution {public: int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { vector<vector<int> > dp = obstacleGrid; if(obstacleGrid[0][0] == 1) return 0; else dp[0][0] = 1; for(int i = 0; i < dp.size(); ++ i) { for(int j = 0; j < dp[i].size(); j ++) { if(i == 0 && j == 0) continue; if(obstacleGrid[i][j] == 1) { dp[i][j] = 0; continue; } int up = 0; int bf = 0; if(i - 1 >= 0) up = dp[i - 1][j]; if(j - 1 >= 0) bf = dp[i][j - 1]; dp[i][j] = up + bf; } } return dp[dp.size() - 1][dp[0].size() - 1]; }};
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
- JavaEE-JPA
- 【leetcode】9. Palindrome Number
- mvc-路由类
- android高仿钉钉和小米的日历控件
- *.hbm.xml 映射配置文件
- Leetcode Unique Paths II
- c#中如何折叠代码段
- 安装MYSQL
- AngularJS 过滤器
- 链表通讯录
- 欢迎使用CSDN-markdown编辑器
- 查看python安装路径
- oam Not Send Authorization Responses
- 软考+软件设计师试题+解答