63. Unique Paths II
2016-03-21 11:18
501 查看
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
in the grid.
For example,
There is one obstacle in the middle of a 3x3 grid as illustrated below.
The total number of unique paths is
Note: m and n will be at most 100.
Subscribe to see which companies asked this question
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
1and
0respectively
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.
Note: m and n will be at most 100.
Subscribe to see which companies asked this question
public class Solution { public int uniquePathsWithObstacles(int[][] o) { int [][] list = new int [o.length][o[0].length];//第一列 for(int i = 0;i<o.length;i++){ if(o[i][0]==1)break; list[i][0]=1; } for(int i = 0;i<o[0].length;i++){ if(o[0][i]==1)break; list[0][i]=1; } for(int i = 1;i<o.length;i++){ for(int j = 1;j<o[0].length;j++){ if(o[i][j]==1)continue; list[i][j]=list[i-1][j]+list[i][j-1]; } } return list[o.length-1][o[0].length-1]; } }
相关文章推荐
- 增加Ueditor在线管理图片删除功能
- 百度编辑器ueditor代码高亮效果前台不显示的解决方法
- RegQueryValueEx详解
- Ueditor结合七牛云存储上传图片、附件和图片在线管理的实现
- ueditor不自动加P,不转义解决方法
- ueditor默认字体和字号修改
- 织梦dede更换ueditor1.4.3,及单页栏目编辑器栏目内容、单页无法保存(原创最新)
- String、StringBuffer与StringBuilder之间区别
- Invalid layout of java.lang.String at value 解决办法(彻底解决)
- uiview常用方法
- Query 允许链接(链式语法)。
- POJ1679 The Unique MST(次小生成树)
- require(),include(),require_once()和include_once()区别
- 334. Increasing Triplet Subsequence
- Column ‘nature’ has duplicated value ‘婆婆妈妈’ in SET
- UCenter info: MySQL Query Error SQL:SELECT value FROM [Table]vars WHERE name=\'noteexists2′ Error:SELECT command denied to use
- Codeforces 645E Intellectual Inquiry (dp不同子序列计数)
- php图像函数 imagecreatetruecolor()和imagecreate()的区别
- dedecms添加新变量提示 Request var not allow
- iOS 之 UITableViewCell 分割线左边没有顶格 解决方法