LeetCode:Unique Paths II
来源:互联网 发布:数据分析模型有哪些 编辑:程序博客网 时间:2024/05/29 15:37
题目描述:
Follow up for "Unique Paths":
Now consider if some obstacles are added to the grids. How many unique paths would there be?
An obstacle and empty space is marked as 1
and 0
respectively in the grid.
For example,
There is one obstacle in the middle of a 3x3 grid as illustrated below.
[ [0,0,0], [0,1,0], [0,0,0]]
The total number of unique paths is 2
.
代码:
int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid){ int i,j; int m = obstacleGrid.size(); int n = obstacleGrid[0].size(); int ** pathCount = (int**)(malloc(sizeof(int*)*m)); for(i = 0;i < m;i++) pathCount[i] = (int*)malloc(sizeof(int)*n); for(i = 0;i < n;i++) if(obstacleGrid[0][i] == 0) pathCount[0][i] = 1; else break; for(;i < n;i++) pathCount[0][i] = 0; for(i = 0;i < m;i++) if(obstacleGrid[i][0] == 0) pathCount[i][0] = 1; else break; for(;i < m;i++) pathCount[i][0] = 0; for(i = 1;i < m;i++) for(j = 1;j < n;j++) { if(obstacleGrid[i][j] == 1) pathCount[i][j] = 0; else pathCount[i][j] = pathCount[i-1][j] + pathCount[i][j-1]; } return pathCount[m-1][n-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
- TwonkyMedia6.0.38
- 欧姆龙PLC的FINS协议解释(实测通过)
- JavaScript权威指南_23_第4章_表达式和运算符_4.9-关系表达式
- linux学习(11)磁盘与目录的容量(df,du),文件链接(ln)
- windows8.1 x64位编译pgmodeler过程记录
- LeetCode:Unique Paths II
- CKEditor 使用
- 十字链表构建矩阵
- JavaScript权威指南_24_第4章_表达式和运算符_4.10-逻辑表达式
- 【CSS】div图层边界对英文换行控制的问题
- windows NT key features
- BZOJ 3143 HNOI2013 游走 期望DP+高斯消元
- android eclipse ADB server didn't ACK * failed to start daemon *
- Windows(VS2008) 下 build tesseract