Unique Paths II
来源:互联网 发布:条形码数据采集器用法 编辑:程序博客网 时间:2024/06/06 02:12
class Solution {public: int paths[100][100]; int uniquePathsWithObstacles(vector<vector<int>>& obstacleGrid) { int m = obstacleGrid.size(), n = 0; if(0 != m) n = obstacleGrid[0].size(); if(0 == n || 0 == m) return 0; for(int i = 0; i < m; ++i){ if(1 == obstacleGrid[i][0]){ while(i < m) paths[i++][0] = 0; }else{ paths[i][0] = 1; } } for(int j = 0; j < n; ++j){ if(1 == obstacleGrid[0][j]){ while(j < n) paths[0][j++] = 0; }else{ paths[0][j] = 1; } } for(int i = 1; i < m; ++i){ for(int j = 1; j < n; ++j){ if(1 == obstacleGrid[i][j]) paths[i][j] = 0; else paths[i][j] = paths[i-1][j] + paths[i][j-1]; } } return paths[m-1][n-1]; }};
阅读全文
0 0
- 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
- Unique Paths II
- Android开发用Intent跳转到系统应用大全总结
- 关于Js的isNaN()函数
- 常用SQL命令
- eclipse/android studio下如何使用第三方模拟器
- Ubuntu安装cuDNN
- Unique Paths II
- SPI协议及其工作原理浅析
- find the mincost route
- hiho #1539 : 数组重排3(bfs)
- C++抽象设计目的
- 正则表达式之过滤敏感词
- linux下c语言入门04 main函数的编写
- XML
- 同步函数与异步函数