不同的路径 II
2015-09-09 19:13
323 查看
class Solution { public: /** * @param obstacleGrid: A list of lists of integers * @return: An integer */ int uniquePathsWithObstacles(vector<vector<int> > &obstacleGrid) { // write your code here int m = obstacleGrid.size(); if(m==0) return 0; int n = obstacleGrid[0].size(); int a[m] ; int temp=100; for(int i=0;i<m;++i){ a[i][0]=1; if(obstacleGrid[i][0]==1){ temp = i; a[i][0]=0; } if(i>=temp) a[i][0]=0; } temp = 100; for(int j=0;j<n;++j){ a[0][j]=1; if(obstacleGrid[0][j]==1){ temp = j; a[0][j]=0; } if(j>=temp) a[0][j]=0; } for(int i =1;i < m;++i){ for(int j =1;j<n;++j){ a[i][j]=a[i-1][j]+a[i][j-1]; if(obstacleGrid[i][j]==1) a[i][j]=0; } } return a[m-1][n-1]; } };
相关文章推荐
- c++运算符重载
- git patch 的用法
- Java泛型中的标记符含义
- 哈希综述的简单整理
- large-scale analysis of malware downloaders
- 数组中奇数偶数的拆分
- 常见的软件滤波算法
- java上传图片放大(小图等比放大,大图等比裁剪)
- 日志系统
- [sed] 保持空间
- Codeforces 543A Writing Code
- python问题:IndentationError:expected an indent
- Java quartz 定时任务
- 数据结构与算法—论证任意二叉树度数为2的节点的个数等于叶节点个数减1
- 构造函数
- IOS中的网络请求
- C语言(11)--回文日、确定等式、fflush(stdin)、将十进制数转换成n进制数、二分法解方程
- “Bean named XXX must be of type[XXX], but was actually of type[XXX]”
- java中将type=date的时间转换成北京时间,并返回字符串型
- 用Collection对list中进行排序