Unique PatUnique Paths II
来源:互联网 发布:淘宝虚拟商品怎么上架 编辑:程序博客网 时间:2024/05/21 02:33
class Solution {public: int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { if(obstacleGrid.size()==0) return 0; int wide=obstacleGrid.size(); int len=obstacleGrid[0].size(); vector<vector<int>>f(wide,vector<int>(len)); f[0][0]=1-obstacleGrid[0][0]; for(int i=1;i<len;i++) if(obstacleGrid[0][i]==0&&f[0][i-1]!=0) f[0][i]=1; else f[0][i]=0; for(int j=1;j<wide;j++) if(obstacleGrid[j][0]==0&&f[j-1][0]!=0) f[j][0]=1; else f[j][0]=0; for(int i=1;i<wide;i++) for(int j=1;j<len;j++) { if(obstacleGrid[i][j]==1) f[i][j]=0; else if(obstacleGrid[i-1][j]==1&&obstacleGrid[i][j-1]==1) f[i][j]=0; else if(obstacleGrid[i-1][j]==1) f[i][j]=f[i][j-1]; else if(obstacleGrid[i][j-1]==1) f[i][j]=f[i-1][j]; else f[i][j]=f[i][j-1]+f[i-1][j]; } return f[wide-1][len-1]; }};if else 真多
0 0
- Unique PatUnique Paths II
- Unique Paths & Unique Paths II
- Unique Paths &&Unique Paths II
- Unique Paths & Unique Paths II
- Unique Paths & Unique Paths II
- LeetCode: Unique Paths II
- [Leetcode] Unique Paths II
- LeetCode : Unique Paths II
- Unique Paths II
- [LeetCode] Unique Paths II
- unique paths II
- Unique Paths II
- [LeetCode]Unique Paths II
- Unique Paths II
- Unique Paths II
- Unique Paths II
- Unique Paths II
- [leetcode]Unique Paths II
- I Love This Game 2115
- C语言基础笔试面试题
- Java之Semaphone
- 连载:面向对象葵花宝典:思想、技巧与实践(5) - 面向对象迷思:面向对象导致性能下降?
- Error: Unable to access jarfile ..\lib\proguard.jar
- Unique PatUnique Paths II
- JS-原型对象的理解
- ACM练习建议
- 不能从const char指针转换为LPCWSTR的原因及解决方法
- 哥德巴赫猜想
- 硕士论文专业定做网站
- dom4j
- AppleScript
- 解决 Errors running builder 'DeploymentBuilder' on project '